/** Call this program, CopyingFile, with as command line parameters the name
  * of a text file to be copied from and the name of the file to 
  * be copied to. It will carry out the copying. It uses a PrintWriter
  */

import java.io.*;
import java.util.*;

public class CopyingFile {
    public static void main(String[] args) {
	if (args.length != 2) {
	   System.out.println("usage: java CopyingFile filefrom fileto");
	   System.exit(1);
	}
	String filefrom = args[0];
	String fileto = args[1];
	try {
	    Scanner rd = null;
	    PrintWriter wd = null;
	    try {
		rd = new Scanner( new File(filefrom) );
//		wd = new PrintWriter( new File(fileto) );
		wd = new PrintWriter( fileto );
		while ( rd.hasNextLine() ) {
		    String aline = rd.nextLine();
		    wd.println(aline);
		}
	    } finally {
		if (rd != null)
		    rd.close();
		if (wd != null)
		    wd.close();
	    }
	} catch (FileNotFoundException e) {
	    System.out.println(e);
	} catch (IOException e) {
	    e.printStackTrace(); // Just to see different things we may do with an exception
	}
	System.exit(0);
    }
}
