chn.util
Class FileInput
java.lang.Object
|
+--chn.util.SimpleIO
|
+--chn.util.FileInput
- public class FileInput
- extends SimpleIO
|
Constructor Summary |
FileInput(java.lang.String fileName)
Constructs the FileInput object with for the given file. |
FileInput(java.lang.String fileName,
java.lang.String delims)
Constructs the FileInput object with for the given file. |
|
Method Summary |
void |
close()
Close the input file. |
boolean |
hasMoreLines()
|
boolean |
hasMoreTokens()
Reads ahead to verify whether there are more tokens to be read. |
java.lang.String |
readLine()
Flushes any remaining tokens on the current input line, then reads the
next full line input as a String and returns it (including an empty line). |
java.lang.String |
readToken()
Reads and returns the next token from the current line. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
FileInput
public FileInput(java.lang.String fileName)
- Constructs the FileInput object with for the given file. Uses default
delimiters, space, tab, formfeed. Newline and return characters
terminate the input of the current line.
FileInput
public FileInput(java.lang.String fileName,
java.lang.String delims)
- Constructs the FileInput object with for the given file. Uses given
delimiters. Newline and return characters
terminate the input of the current line.
close
public void close()
- Close the input file. Any attempt to read from this object after this
function has been called will result in an error.
hasMoreLines
public boolean hasMoreLines()
- Returns:
- true if there are more lines to be read, otherwise false
hasMoreTokens
public boolean hasMoreTokens()
- Reads ahead to verify whether there are more tokens to be read.
Will read past any empty lines if the current line has no more tokens.
- Returns:
- true if there are unread tokens, false otherwise
readToken
public java.lang.String readToken()
- Reads and returns the next token from the current line. A token is a
String of characters separated by the specified delimiters. If the current
input line has no more unread tokens, reads the first token from the first
non-empty line entered.
If there are no more unread tokens, prints an error message and terminates program.
- Overrides:
readToken in class SimpleIO
- Returns:
- the next String token from input, as determined by delimiters
readLine
public java.lang.String readLine()
- Flushes any remaining tokens on the current input line, then reads the
next full line input as a String and returns it (including an empty line).
If there are no more unread lines, prints an error message and terminates program.
- Overrides:
readLine in class SimpleIO
- Returns:
- next line read as a String