Create StreamTokenizer from FileReader : StreamTokenizer « File Input Output « Java






Create StreamTokenizer from FileReader

 

import java.io.FileReader;
import java.io.StreamTokenizer;

public class ExtractTokens {
  public static void main(String[] args) throws Exception {
    FileReader fr = null;

    fr = new FileReader(args[0]);

    StreamTokenizer st = new StreamTokenizer(fr);
    st.lowerCaseMode(true);

    while (st.nextToken() != StreamTokenizer.TT_EOF) {
      switch (st.ttype) {
      case '\'':
      case '"':
        System.out.println("String = " + st.sval);
        break;

      case StreamTokenizer.TT_EOL:
        System.out.println("End-of-line");
        break;

      case StreamTokenizer.TT_NUMBER:
        System.out.println("Number = " + st.nval);
        break;

      case StreamTokenizer.TT_WORD:
        System.out.println("Word = " + st.sval);
        break;

      default:
        System.out.println("Other = " + (char) st.ttype);
      }
    }
  }
}

   
  








Related examples in the same category

1.Create StreamTokenizer from BufferedReader
2.Extract Tokens with StreamTokenizer
3.Read file with StreamTokenizer
4.Set whitespaceChars
5.Set eolIsSignificant
6.Deal with StreamTokenizer.TT_WORD, StreamTokenizer.TT_NUMBER
7.Using StreamTokenizer to count words and numbers in a file
8.Tokenizing Java Source Code
9.Stream Token