/* Punters Lounge JAVA programming course * * Lesson72.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 Lesson72 { public static void main(String[ ] args) 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 OutFile = 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) { if ( (ReadChar > 64) & (ReadChar < 89) ) ReadChar = ReadChar + 32; else if ( (ReadChar > 96) & (ReadChar < 121) ) ReadChar = ReadChar - 32; OutFile.write(ReadChar); } // when the file is read close the stream to the file ReadFile.close(); OutFile.close(); } }