import java.io.*; /** * Copies the file specified by args[0] to the file specified by args[1]. */ public class FileCopy { public static void main(String[] args) throws IOException { /* The straems could have been created directly from args[0] and args[1], the two File objects below are not neccesary to create. */ File inputFile = new File(args[0]); File outputFile = new File(args[1]); FileReader in = new FileReader(inputFile); FileWriter out = new FileWriter(outputFile); int c; //Read returns an int, but it is never more than 16 bits long. while ((c = in.read()) != -1) { out.write(c); } /* It is very important to close the out stream. If not it might never be flushed to the disk. */ in.close(); out.close(); } }