FileDocCategorySizeDatePackage
TextFileCopier.javaAPI DocExample852Sun Mar 28 19:09:08 BST 1999None

TextFileCopier

public class TextFileCopier extends Object

Fields Summary
Constructors Summary
Methods Summary
public static voidcopyFile(java.lang.String file1, java.lang.String file2)

    
    File infile = new File(file1);
    File outfile = new File(file2);
      
    if (infile.getCanonicalPath().equals(outfile.getCanonicalPath())) {
      return;
    }

    FileReader fr = new FileReader(infile);
    FileWriter fw = new FileWriter(outfile);
    
    while (true) {
      int i = fr.read();
      if (i == -1) break;
      fw.write(i);
    }
    
    fw.close();
    fr.close();
    
  
public static voidmain(java.lang.String[] args)


    if (args.length != 2) {
      System.err.println("Usage: java TextFileCopier file1 file2");
    }
    try {
      copyFile(args[0], args[1]);
    }
    catch (IOException e) {
      System.err.println(e);
    }