Source of CopyTextFile.java


  1: /* 
  2:  * Copyright (c) 1999-2002, Xiaoping Jia.  
  3:  * All Rights Reserved. 
  4:  */
  5: 
  6: import  java.io.*;
  7: 
  8: /**
  9:  *  This program copies a text file to antoher file. 
 10:  *  The first argument is the input file name. The second argument is the output file name.
 11:  */
 12: public class CopyTextFile {
 13: 
 14:   public static void main(String[] args) {
 15:     if (args.length >= 2) {
 16:       try {
 17:         BufferedReader in = new BufferedReader(
 18:                                 new FileReader(args[0]));
 19: 
 20:         PrintWriter out = new PrintWriter(
 21:                               new BufferedWriter(
 22:                                   new FileWriter(args[1])));
 23:         String  line;
 24:         while ((line = in.readLine()) != null) {
 25:           out.println(line);
 26:         }
 27:         out.flush();
 28:         out.close();
 29:       } catch (IOException e) {}
 30:     }
 31:   }
 32: 
 33: }
 34: