/*
TextReaderTest
This program defines a class called 'TextReader' which is intended to
simplify reading text files a line at a time. The TextReader class
manages all the intermediate files that are needed for this operation,
so the class that uses it can read a text file without worry about these
details
*/
import java.io.*;
class TextReader
{
BufferedReader br;
public TextReader(String filename) throws java.io.IOException, java.io.FileNotFoundException
{
File aFile =new File(filename);
FileInputStream fis = new FileInputStream(aFile);
InputStreamReader isr = new InputStreamReader (fis);
br = new BufferedReader (isr);
}
String readLine() throws java.io.FileNotFoundException, java.io.IOException
{
return br.readLine();
}
}
/*
TextReaderTest
This class tests the TextReader by opening a file and reading the first line
from it
*/
class TextReaderTest
{
public static void main (String args[])
{
try
{
TextReader textReader = new TextReader ("TextReaderTest.java");
String s = textReader.readLine();
System.out.println(s);
}
catch (Exception e)
{
System.out.println(e.toString());
}
}
}
©1994-2003 Kevin Boone, all rights reserved