Copy data form one file to another file using java


Write a program to copy data from one file to another file.

Write java code to copy data from one file to another file.

Write a program to coping data in file using java.

import java.io.*;

public class copydatafromeonefiletoanotherfile {

public static void main(String args[]){

        try{

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

           //view older file

            FileInputStream f=new FileInputStream("rajendrafile.txt");

            //create file

            FileOutputStream f1=new FileOutputStream("rajendralamrorfile.txt");

          //enter the data in the created file

            System.out.println("Copy file");

           int c;

           //read data from one file and write data in the another file

            while((c=f.read()) != -1)

            { f1.write(c);}

           

            f.close(); //close the file(rajendrafiel.txt)

            f1.close();//new created file close(rajendralamror.txt)

            System.out.println("File is created and data is copied");

        }catch(IOException e){ }

    }

}

No comments:

Post a Comment