by Dinesh Thakur Category: Stream

We use two classes FileInputStream, FileOutputStream i.e to read data from one file and write it to another file.

Here is the Java Example for Copy Data From One File to Another:

import java.io.*;

class CopyDataFiletoFile
{
             public static void main(String args[])throws IOException
        {
              FileInputStream Fread =new FileInputStream("Hello.txt");
              FileOutputStream Fwrite=new FileOutputStream("Hello1.txt") ;
              System.out.println("File is Copied");
              int c;
              while((c=Fread.read())!=-1)
              Fwrite.write((char)c);
              Fread.close();
              Fwrite.close();
         }
}

 

Copy Data From One File to Another File

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Search Content







Popular Article