 Hello friends, I am Sanjay Gupta. In this video, I am going to demonstrate you how you can append data into a file using Java program. Before starting, you can subscribe my YouTube channel by clicking on the link which is available at bottom right corner of this video. You can download my app Takimiz that is available on Google Play. You can connect with me by following these details which are available in front of you. You can see a code which is available in front of you. It is importing three classes file, file, output, stream and scanner. Two classes are available in IO, package and one in utl. Name of file is file write. Sorry, name of user defined classes file write. Name of method which is containing all the statement is main. Inside main try block is defined, which is containing some statements. First of all, a file is file object is created. Obesa file which is opening a file file dot txt. Then if condition is available, if file is already available, then this if condition will become false. If it is not available, then this if condition will become true. Then new file will be created using create new file method calling. If file is created successfully, then this message file created successfully will be printed on console. Otherwise file creation failed will be displayed. System dot exit will terminate the execution of the program if file is not created. But if file is already available, then control will be transferred to these statements. Here text variable of string class is created. Then scanner object SC is created. Then system dot out dot print ln will print enter text to write into file message on control. Using next line method data will be stored inside text variable. Now file out object is created of file input stream. This file output sorry file output stream. This file output stream is a predefined class. Here OBJ file which is having name of file. File dot txt is passed in this map sorry in this object creation as an argument. And here true is passed. This true indicates that if you want to write some contents again and again, then that file will be opened in append mode. So append means all the data which you want to write will be added at the end of file. So if you open that file more than one time and if you want to write some data again and again, that all data will be stored in that file and that mode append mode. So you have to use true if you remove true from here, then file will be opened in write mode that is known as overwritten mode. It means previous data will be erased and new data will be stored. But if you want to keep your old data as well as new, then you have to use true here. Now file out dot write method is called here which is having text dot get bytes method. So get bytes method find outs or receives bytes which are available in this text variable which is of string type. So all the data which is in string formats will be converted into byte format and that data will be stored inside this file out object which is linked with obj file and obj file is further linked with file dot txt. In short, all the input will be stored inside file dot txt. Now file out dot close will close the file out object. Then masses file saved will be displayed on console. If any exception will be raised that will be handled by this catch block and error masses will be displayed with the help of ex dot to string method calling. So this is the explanation of this program. Now this code is stored inside the project named Sanjay. I am using eclipse. So eclipse uses a path where this project is to be stored. So this path is D drive practice folder inside D practice folder. Sanjay as project is stored. Here you can see right now no file is available. So first I am executing this code. It will create a new file automatically. You can see that file created successfully. It means it has created a new file. We can check it file dot txt is available here. Now I have to enter a text. So I have entered Sanjay and it is showing file saved. Now we can see this file by opening it. You can see name is available here. Now again I am executing this code. Now it is only asking the text. It is not opening or creating a new file. Now I am entering my surname Gupta again. I am opening this file. You can see that my full name is available in this file. So now I hope you have understood that this file is opened in append mode. Whatever data I am entering, it is appended at end of file. Previous data is available and new data is also available. So if you want to open your file in append mode, then you can use this code. I hope you have understood the concept and the difference between write mode and append mode. Write mode opens file in overwrite mode whereas append mode opens file in the mode which can preserve previous data as well as new data. If you want to watch more programming related videos, you can subscribe my YouTube channel. Thank you for watching this video.