/* Punters Lounge JAVA programming course * * Lesson73.java * * Author : Erik Datapunter * Date : 12/jun/2004 * * Reading from a file and writing to a file, appending * */ // import the library with Input Output objects import java.io.*; public class Lesson73 { public static void main(String[ ] args) throws Exception { /* create a file object of the file to read * create a FileReader object * create a BufferedReader object * we can access the file with the inputfilebuffer object */ File FromFile = new File("in-file.txt"); FileReader ReadFile = new FileReader(FromFile); BufferedReader inputfilebuffer = new BufferedReader(ReadFile); /* create a file object of the file to write * create a FileWriter object * create a BufferedWriter object * we can access the file with the outputfilebuffer object */ File ToFile = new File("out-file.txt"); FileWriter WriteFile = new FileWriter(ToFile); BufferedWriter outputfilebuffer = new BufferedWriter(WriteFile); // a String to hold a single line int ReadChar; // while we have not yet reached the end of the file, read another character while ((ReadChar = inputfilebuffer.read()) != -1) { if ( (ReadChar > 64) & (ReadChar < 89) ) ReadChar = ReadChar + 32; else if ( (ReadChar > 96) & (ReadChar < 121) ) ReadChar = ReadChar - 32; outputfilebuffer.write(ReadChar); } // when the file is read close the stream to the file inputfilebuffer.close(); outputfilebuffer.close(); } }