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.
  Java Book 
    File Stream  

  1. StreamTokenizer
  2. new StreamTokenizer(Reader r)
  3. new StreamTokenizer(FileReader fileReader)
  4. StreamTokenizer: nval
  5. StreamTokenizer: ttype
  6. StreamTokenizer.TT_EOF
  7. StreamTokenizer.TT_NUMBER
  8. StreamTokenizer.TT_WORD
  9. StreamTokenizer: commentChar(int ch)
  10. StreamTokenizer: eolIsSignificant(boolean b)
  11. StreamTokenizer: lineno()
  12. StreamTokenizer: nextToken()
  13. StreamTokenizer: ordinaryChar(int ch)
  14. StreamTokenizer: wordChars((int low, int hi))