How to copy one file into another
This java code is simple i/o example to copy the content of one file into
another file . You provide the path of the file content and file to copy .
package IO;
import java.io.*;
import java.lang.*;
class FileCopy
{
public static void main(String[] args) {
File infile=new File("/Users/macbook/Desktop/file1");
File outfile=new File("/Users/macbook/Desktop/file2");
FileReader ins=null;
FileWriter outs=null;
try
{
ins=new FileReader(infile);
outs=new FileWriter(outfile);
int ch; while((ch=ins.read())!=-1)
{
outs.write(ch);
}
ins.close();
outs.close();
}
catch(IOException e)
{
System.out.println(e);
}
System.out.println("File Copied.");
}
}
In the code file reader anf file writer is used to
read and write the file . If copy successful .then
you can see print
File copied.
How to copy one file into another
Reviewed by Mukesh Jha
on
9:01 PM
Rating:
No comments:
Add your comment