/** 
 * This program is an example from the book "Internet 
 * programming with Java" by Svetlin Nakov. It is freeware. 
 * For more information: http://www.nakov.com/books/inetjava/ 
 */ 
import java.io.*; 
 
public class BinaryFileCopier { 
    public static void main(String args[]) throws IOException { 
        FileInputStream inFile = 
            new FileInputStream("input.bin"); 
        FileOutputStream outFile = 
            new FileOutputStream("output.bin"); 
        byte buf[] = new byte[1024]; 
        while (true) { 
            int bytesRead = inFile.read(buf); 
            if (bytesRead == -1) break; 
            outFile.write(buf, 0, bytesRead); 
        } 
        outFile.flush(); 
        outFile.close(); 
        inFile.close(); 
    } 
}
Back to Internet Programming with Java books's web site