Class LineReader

java.lang.Object
  extended by LineReader

public class LineReader
extends java.lang.Object

Simple class to read lines in from a text file. To use, create a LineReader object, then send it the readLine() message as many times as desired. When readLine() returns the value null, the last line has been read, and the file is automatically closed for you.

Version:
3.0
Author:
David Matuszek

Method Summary
 void close()
          Closes the file used by this LineReader.
static LineReader createReader()
          Opens a dialog box with a default message asking the user to choose a file to be read, and returns a LineReader for the chosen file.
static LineReader createReader(java.lang.String message)
          Opens a dialog box that asks the user to choose a file to be read, and returns a LineReader for the chosen file.
static void main(java.lang.String[] args)
          Main method used exclusively for testing.
 java.lang.String readLine()
          Once you have created a LineReader for a file, each call to readLine() will return another line from that file.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createReader

public static LineReader createReader(java.lang.String message)
Opens a dialog box that asks the user to choose a file to be read, and returns a LineReader for the chosen file. If the user cancels the dialog, or if the file cannot be read, this method returns null.

Parameters:
message - The message displayed at the top of the dialog box.
Returns:
A LineReader object.

createReader

public static LineReader createReader()
Opens a dialog box with a default message asking the user to choose a file to be read, and returns a LineReader for the chosen file. If the user cancels the dialog, or if the file cannot be read, this method returns null.

Returns:
A LineReader object.

readLine

public java.lang.String readLine()
Once you have created a LineReader for a file, each call to readLine() will return another line from that file. After the last line in read, readLine() will return null instead of a String, and will automatically close the file.


close

public void close()
Closes the file used by this LineReader. It is harmless to call this method if the file has already been closed.


main

public static void main(java.lang.String[] args)
Main method used exclusively for testing.