// File: ReadFileChar.java import java.io.*; /** ReadFileChar -- This program demonstrates a method for reading * single characters from a file. It uses a buffered approach to * preserve performance. * * @author David & Chris Green */ public class ReadFileChar { public static void main(String[] args) throws IOException { BufferedReader in = null; int ich; // Unicode char in binary so EOF can be sensed char ch; // Unicode char as char int ch_count=0; // count of chars read // read from test file in = new BufferedReader( new FileReader( "test.txt" )); while ( (ich=in.read()) != -1) { // extract character ch = (char) ich; ch_count++; System.out.println( "count = " + ch_count + " int = " + ich + " char = " + ch ); } in.close(); } }