Copy file character by character with FileReader and FileWriter : FileWriter « File Input Output « Java






Copy file character by character with FileReader and FileWriter


import java.io.FileReader;
import java.io.FileWriter;

class FileCopy {

  public static void main(String args[]) throws Exception {

    FileReader fr = new FileReader(args[0]);

    // Create a file writer
    FileWriter fw = new FileWriter(args[1]);

    // Read and copy characters
    int i;
    while ((i = fr.read()) != -1) {
      fw.write(i);
    }
    fw.close();

    fr.close();
  }
}

 








Related examples in the same category

1.BufferedWriter out of FileWriter
2.Write string to file with FileWriter
3.Copy Characters between FileReader and FileWriter
4.extends FilterWriter and extends FilterReader