/*
    This program opens the text file given as the first argument and 
    prints it to the file given in the second argument.

    Written by:  H. Conrad Cunningham, 9 Sept. 1996

    Note:  18 January 1999.  This program should be modified to use the 
           Reader classes.
y*/

import java.io.*;

public class ByteFileCopy {

    public static void copy(String source_name, String dest_name) 
        throws IOException
    /*  Pre:   source_name denotes an existing file.
               dest_name denotes a new file (or one that can be
	           overwritten).
        Post:  The Ascii characters from file source_name have been 
	           copied to file dest_name.
        Note:  IOExceptions are not handled.
    */
    {   // Open file source_name for input on data stream in
        FileInputStream source = new FileInputStream(source_name);
        DataInputStream in = new DataInputStream(source);
	
	// Open file dest_name for output on print stream out
        FileOutputStream destination = new FileOutputStream(dest_name);
        PrintStream out = new PrintStream(destination);

	// Copy characters from in to out
	while (in.available() > 0)
        {   char ch = (char)in.readByte();
            out.print(ch);  // writes as Ascii, not Unicode
	}

	// Close both files
	in.close();
	out.close();
    }

    public static void main(String[] args) throws IOException
    /*  Pre:   The first command line argument denotes an existing file. 
               The second command line argument denotes a new file (or
                   one that can be overwritten).
        Post:  The Ascii characters from the file given by the first argument  
                   have been copied to the file given by the second.
        Note:  IOExceptions are not handled.
    */
    {   if (args.length != 2)
            System.err.println("Usage: java ByteFileCopy " + 
                    "<source file> <destination file>");
        else 
	    copy(args[0], args[1]);
    }
}
