/**
* Java copies the contents of one file to another file
*/
Import Java.io.File;
Import Java.io.FileInputStream;
Import java.io.FileNotFoundException;
Import Java.io.FileOutputStream;
Import java.io.IOException;
public class Fileinputoutputstreamtest {
public static void Main (string[] args) {
File AF = new file ("A.txt");
File BF = new file ("B.txt");
FileInputStream is = null;
FileOutputStream OS = null;
if (!bf.exists ()) {
try {
Bf.createnewfile ();
} catch (IOException e) {
E.printstacktrace ();
}
}
try {
is = new FileInputStream (AF);
OS = new FileOutputStream (BF);
byte b[] = new byte[1024];
int Len;
try {
Len = Is.read (b);
while (len! =-1) {
Os.write (b, 0, Len);
Len = Is.read (b);
}
} catch (IOException e) {
E.printstacktrace ();
}
} catch (FileNotFoundException e) {
E.printstacktrace ();
}finally{
try {
if (is! = null) is.close ();
if (OS! = null) os.close ();
} catch (IOException e) {
E.printstacktrace ();
}
}
}
}
Java copies the contents of one file to a different file