/*                                      
 * SimpleArrayCopy.java 
 *
 * Version: 
 *     $Id: SimpleArrayCopy.java,v 1.1 2002/03/22 18:34:38 jmg Exp $ 
 * 
 * Revisions: 
 *     $Log: SimpleArrayCopy.java,v $
 *     Revision 1.1  2002/03/22 18:34:38  jmg
 *     Initial revision
 * 
 */

// We need classes from the Java I/O package
import java.io.*;

/**
 * Class that performs a simple copy from one binary file to another
 * using arrays
 *
 * @author Joe Geigel
 */
public class SimpleArrayCopy {
    /**
     * main program.  Takes two filenames as arguments.  The first
     * is the name of the source file, the second is the name of the 
     * destination file
     */
    public static void main (String args[])
    {
	// Commandline check
	if (args.length != 2) {
	    System.out.println 
		("usage: java SimpleArrayCopy <source> <destination>");
	    System.exit(1);
	}

	// Remember that most IO operations will throw an IOException
	// if things go wrong
	try {
	    FileInputStream fin = new FileInputStream (args[0]);
	    FileOutputStream fout = new FileOutputStream (args[1]);

	    int buflen = 80;
	    byte buffer[] = new byte[buflen];
	    int n;
	    while ((n = fin.read(buffer)) != -1) 
		fout.write (buffer,0,n);

	    fin.close();
	    fout.close();
	}
	catch (IOException E){
	    System.out.println ("Problem: " + E.getMessage());
	}
    }
}
