/* Punters Lounge JAVA programming course * * Lesson7a.java * * Author : Erik Datapunter * Date : 12/jun/2004 * * Reading from a file * */ // import the library with Input Output objects import java.io.*; public class Lesson7a { 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); // 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) { // display the character on the screen as a numerical value // use write() in stead of println() to display as letters // System.out.println(ReadChar); System.out.write(ReadChar); } // when the file is read close the stream to the file ReadFile.close(); } }