/* Punters Lounge JAVA programming course * * Lesson7b.java * * Author : Erik Datapunter * Date : 12/jun/2004 * * Reading from a file and writing to a file * */ // import the library with Input Output objects import java.io.*; public class Lesson7b { public static void main(String[ ] arguments) throws Exception { // create a File object pointing to a physical file File FromFile = new File("in-file.txt"); // create a FileReader object to use to read from the file FileReader ReadFile = new FileReader(FromFile); // create a File object pointing to a physical file File ToFile = new File("out-file.txt"); // create a FileWriter object to use to write to the file FileWriter WriteFile = new FileWriter(ToFile); // an integer to read each character as a numerical value int ReadChar = 0; // while we have not yet reached the end of the file, read another character while ((ReadChar = ReadFile.read()) != -1) { // write the character to the output file WriteFile.write(ReadChar); } // when the file is read close the stream to both the input file and the output file ReadFile.close(); WriteFile.close(); } }