 Hello friends, I am Sanjay Gupta. In this video, I am going to demonstrate you how you can write some data into a file in Java. Before starting, you can click on the link which is available at the bottom right corner of this video so that you can subscribe my YouTube channel. You can download my app Techimus that is available on Google Play. You can connect with me by following these details which are available in front of you. Now coming onto the topic, here I am going to demonstrate you how you can write some data into a file. For that purpose, I have imported file, file output screen and scanner classes. First two classes are available in IO packages and scanner classes available in UTEL packages. Then file write class is available here which is containing all the statements. Then main method is defined. Inside main method, an object obj file of file class is created. Inside that file1.txt is passed as an argument. Then if statement, if condition is available which is calling exist method based on obj file. So if this file is already available, then this if condition will become false. If file is not available, then this if condition will become true so that a new file will be created using this second if statement. Second if statement is calling create new file method. It will create new file and this message file created successfully will be displayed on console. If file creation is unsuccessful, then this message will be displayed and system.exit will terminate the execution of the program. But if file is already available, this if condition will become false and control will be transferred automatically to the remaining statements. Here text variable of string class is available. Then scanner class object sc is created. Then system.out.println will print enter text to write into file. So that text which is entered by the user will be read by sc.nextline method and that input values will be stored inside text variable. Now file outputs frame object file out is created and it is linked with obj file and obj file is linked with file 1.txt which you can see available here. File 1 is linked with obj file. So we are directly using obj file object which is already linked with file 1.txt. So we have to use file out object right now. So file out object is calling write method. Inside write method text.getbytes method is called. So text.getbytes method will convert all the content into byte format and the data will be stored inside file 1.txt. After writing file out is closed and system.out.println will print file save message on console. These all statements are written inside try block. So if any exception will be raised then that will be catched while this catch block and the statement system.out.println will print this message on console using ex.toString method. So the exception error messages will be displayed on console using toString. Now I am going to execute this code. Before that I am opening the location where file will be created. So you can see that I am saving this file in this project sanjay. So I am opening computer, d drive, practice folder. Inside this folder package is available named as sanjay. You can see that no file is created right now here. So now I am executing this code. You can see that file created successfully. So file is not available. That's why new file is created. It is asking for a text. So I am entering sanjay. File saved message is displayed here. Now you can see that file 1.txt is created. I am double clicking on it. You can see my name is available in this file. Now again I am executing this code. You can see that now new file is not created because file 1.txt is already available. Now I am storing new name because inside this file. So old name will be removed and new name is assigned here. So this file is open in write mode. So it is overriding every time whenever I am executing the code. So friends, I hope you have understood how you can read input from user and you can write that input into the file using file handling in Java. So implement this code at your own so that you can understand the concept well. The advantage of file handling is that you can store the entered values permanently in a particular text file that will be stored permanently inside your computer's hard disk and you can access that file by moving into your project. So if your Java code is not available and it is deleted, after that deletion your file is available. You can see the output at any time whenever you want to use it. You can also use this file as input for other Java programs. So if you want to watch more programming related videos, you can subscribe my YouTube channel. Thank you for watching this video.