 Hello friends. I am Sanjay Gupta in this video. I am going to demonstrate you how you copy contents of a file into another using a Java program before starting. You can subscribe my YouTube channel by clicking on the bottom right corner of this video. You can download my app that is available on Google Play. You can connect with me by following these details which are available in front of you. Now with the help of this example, I will be demonstrating how you can copy content of a file into another. So I have imported three classes file input stream, file output stream and IO exception. All three classes are available in IO package. File copy is the name of user defined class which is containing main method. Inside main method, I have created one object source file of file input stream class. Second object target file of file output stream class. So a source file will open a file in read mode and target file will open a file in write mode because of file input stream and file output stream. Name of file is file 1.exe which will open in read mode. File 2.exe will open in write mode. Then int byte value variable is declared. Then a loop is available. This loop is containing a single statement. I can use braces here so that you can recognize it well. While byte value equals to source file dot read. So this read method is responsible for reading contents from the file and source file dot read. This read method is called through source file. So source file is linked with file 1.exe. That's why the content will read from file 1.exe and the result will be stored inside byte value. So if a particular value will be read properly then this condition will be true. It will not be equals to minus 1 but if nothing will be read. So at the end in all files EOF is present. So if file is empty so at last EOF will be read whose value is minus 1. So if that value is equals to minus 1 then this loop will get terminated. So if contents are available then loop will repeat otherwise loop will be terminated. So inside loop write method is called through target file. So target file is linked with file 2.exe and it is writing byte value variable inside the file. It means read method is reading contents from file 1. Contents are stored inside byte value and using byte value they are stored using write method into target file that is file 2.exe. So in short file 1 contains are copying into file 2 file. Then after completion of loop source file and target file objects are closed then a message file copied successfully will be displayed on console. All these statements are enclosed inside try block so that if any exception is raised that will be handled by the catch block. All exception will be handled by this E reference which is of IO exception class. And then with the help of two string method all the error message will be displayed on console. Now you can see that I have created this class in Sanjay project and I am using eclipse. So eclipse uses a particular path to store all the projects. So in my system this path is D then practice folder inside this practice folder you can see this Sanjay project is available. Here you can see file 1.exe is already available which I have created. It is a notepad file and it is containing my name Sanjay Gupta. Right now there is only one file file 1.exe which is text file. Now I am executing this code. You can see that file copied successfully message displayed on console. Now we have to check the folder or project. You can see now here are two files file 1.exe and file 2.exe and file 2.exe. If I open this file it is also containing my name Sanjay Gupta. So friends with the help of this code I have copied contains of file 1.exe into file 2.exe. And I have used read and write methods of input sorry file input stream class and file output stream class. You can also use this code so that you can copy content of a file into another file. I hope you have understood the concept. If you want to watch more programming related videos you can subscribe my YouTube channel. Thank you for watching this video.