Copy file : File Management

FileInputStream and FileOutputStream classes both use for copy file concepts. FileInputStream class reads data from one file. FileOutputStream class writes into another file.

 

Video on copy file java program.

Program on copy to file to another file.

import java.io.*;

class io7

{

                public static void main(String args[]) throws IOException

                {

                                BufferedReader br= new BufferedReader(new InputStreamReader(System.in));

                                FileInputStream fin = null;

                                FileOutputStream fout = null;

 

                                try

                                {

 

                                                System.out.print(“Enter Original File : “);

                                                String orgFile = br.readLine();

                                                System.out.print(“Enter Copy to File Name : “);

                                                String cpyFile = br.readLine();

 

                                                fin = new FileInputStream(orgFile);

                                                fout = new FileOutputStream(cpyFile);

 

                                                int i;

                                                do

                                                {

                                                                i = fin.read(); // read data from orgFile

                                                                fout.write(i); // write i data into cpyFile

                                                }                                                             

                                                while(i!=-1);

                                }

                                catch(Exception ex){}

                }

}

Output:

Enter Original File: inh9.java

Enter Copy to File Name : copyinh9.java


[sbscrbr_form]

If you have any query on blog example, you can directly comment us or subscribe our website


Earn Money Online

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS

426total visits,4visits today


mayank

Hello, I am Maddy a Java blogger, trainer and developer

Related articles

Leave a Reply

EmailEmail
PrintPrint