import java.io.BufferedOutputStream;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.io.File;
public class FileCopy5{
private static void usage(){
System.out.println("Usage: java FileCopy5 infile outfile");
System.exit(1);
}
public static void main(String [] args){
if (args.length <2)
usage();
File inFile=new File(args[0]);
if (!inFile.canRead()){
System.out.println("Could not open input "
+args[0]);
System.exit(1);
}
File outFile=new File(args[1]);
if (!outFile.canWrite()){
System.out.println("Could not open output "
+args[1]);
System.exit(1);
}
StopWatch clock=new StopWatch();
long bytes=0;
clock.start();
try {
BufferedInputStream in=
new BufferedInputStream(
new FileInputStream(args[0]));
BufferedOutputStream out =
new BufferedOutputStream(
new FileOutputStream(args[1]));
int b=in.read();
while (b>=0){
bytes++;
out.write(b);
b=in.read();
}
out.close();
} catch (IOException e){
System.out.println(e.getMessage());
System.exit(1);
}
clock.stop();
System.out.println(bytes+" bytes copied in "+
clock.getElapsedTime()+"ms");
}
}
//