/*
    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
    Revised by:  H. Conrad Cunningham, 1 October 1996
                 inserted check for one command line argument
		 changed variable name "url" to "urlIn"

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

import java.io.*;

public class TextFileCopy {

    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 lines of text 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 text lines from in to out
        String line;
        for(line = in.readLine(); line != null; line = in.readLine())
	    out.println(line);

	// 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 lines of text 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 TextFileCopy " + 
                    "<source file> <destination file>");
        else 
	    copy(args[0], args[1]);
    }
}
