// file copy program, copying the first argument to the second // the third argument, if `a', means append; `w' or lack of a third // argument, means write-over // reads in byte-by-byte; more advanced forms may be more efficient import java.io.*; public class CpBytes { public static void main (String Arg[]) throws FileNotFoundException, IOException { FileInputStream F1 = new FileInputStream(Arg[0]); FileOutputStream F2; if (Arg.length == 2 || Arg[2].equals("w")) F2 = new FileOutputStream(Arg[1]); else F2 = new FileOutputStream(Arg[1],true); int ByteValue; // has range 0 to 255, so it works for any type // of data while (true) { ByteValue = F1.read(); if (ByteValue == -1) // end-of-file encountered break; else F2.write(ByteValue); } F1.close(); F2.close(); } }