|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectstatalign.io.input.FileTokenReader
public class FileTokenReader
Class that allows reading the contents of a file token by token, without worrying about line ends and whitespace. E.g. files containing ten integers in a single line or ten lines can be handled in a uniform way. Inspired by the C call fscanf(file, "%d", &value). Tokens can be integers, doubles or strings. Separators are any combination of whitespace characters as recognized by the regular expression \s+ .
Constructor Summary | |
---|---|
FileTokenReader(java.lang.String fname)
Constructs a FileTokenReader reading a given file. |
Method Summary | |
---|---|
void |
close()
Closes the underlying file. |
java.lang.Double |
readDbl()
Reads the next token and tries to interpret it as a double value. |
java.lang.Integer |
readInt()
Reads the next token and tries to interpret it as an integer value. |
java.lang.String |
readStr()
Reads the next token and returns it as a String. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public FileTokenReader(java.lang.String fname) throws java.io.IOException
fname
- Name of the file to read
java.io.IOException
- if an I/O error occursMethod Detail |
---|
public java.lang.Double readDbl() throws java.io.IOException
java.io.IOException
- if an I/O error occurs
java.lang.NumberFormatException
- if next token cannot be converted to Doublepublic java.lang.Integer readInt() throws java.io.IOException
java.io.IOException
- if an I/O error occurs
java.lang.NumberFormatException
- if next token cannot be converted to Integerpublic java.lang.String readStr() throws java.io.IOException
java.io.IOException
- if an I/O error occurspublic void close() throws java.io.IOException
java.io.IOException
- if an I/O error occurs
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |