StreamTokenizer breaks up the input stream into tokens.
It has this constructor:
StreamTokenizer(Reader inStream)
inStream must be some form of Reader.
StreamTokenizer defines several methods.
void eolIsSignificant(boolean eolFlag)
If eolFlag is true, the end-of-line characters are returned as tokens. If eolFlag is false, the end-of-line characters are ignored.
The wordChars( ) method is used to specify the range of characters that can be used in words. Its general form is shown here:
void wordChars(int start, int end)
start and end specify the range of valid characters.
The whitespace characters are specified using whitespaceChars( ). It has this general form:
void whitespaceChars(int start, int end)
start and end specify the range of valid whitespace characters.
The next token is obtained from the input stream by calling nextToken( ). It returns the type of token.
StreamTokenizer defines four int constants: TT_EOF, TT_EOL, TT_NUMBER, and TT_WORD.
There are three instance variables.
public double nval
holds the values of numbers as they are recognized.
public String sval
holds the value of any words as they are recognized.
public int ttype
stores the type of token that has just been read by the nextToken( ) method.
If the token is a word, ttype equals TT_WORD.
If the token is a number, ttype equals TT_NUMBER.
If the token is a single character, ttype contains its value.
If an end-of-line condition has been encountered, ttype equals TT_EOL.
If the end of the stream has been encountered, ttype equals TT_EOF.