/** * file : FileWordList.java * desc : Implements a class for reading a list of Words * from a file. */ import java.io.*; public class FileWordList { /** * post : opens `file' for reading words one at a time */ public FileWordList( String fname ) throws FileNotFoundException { filename = fname; reset(); } /** * post : re-opens the file for reading from the beginning */ public void reset() throws FileNotFoundException { FileInputStream f = new FileInputStream( filename ); InputStreamReader i = new InputStreamReader( f ); Reader r = new BufferedReader( i ); fileStream = new StreamTokenizer( r ); } /** * post : returns true <==> no more input waiting */ public boolean isEOF() { return (fileStream.ttype == StreamTokenizer.TT_EOF); } /** * post : returns the next word from the file, or * null if no more words are available */ public Word nextWord() throws IOException { if( isEOF() ) return null; fileStream.nextToken(); if( isEOF() ) return null; return new Word(fileStream.sval); } private String filename; private StreamTokenizer fileStream; } // eof