StreamTokenizer: commentChar(int ch) : StreamTokenizer « java.io « Java by API






StreamTokenizer: commentChar(int ch)

 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;

public class Main {
  public static void main(String args[]) throws IOException {
    BufferedReader inData = new BufferedReader(new InputStreamReader(System.in));
    StreamTokenizer inStream = new StreamTokenizer(inData);
    inStream.commentChar('#');
    boolean eof = false;
    do {
      int token = inStream.nextToken();
      switch (token) {
      case StreamTokenizer.TT_EOF:
        System.out.println("EOF encountered.");
        eof = true;
        break;
      case StreamTokenizer.TT_EOL:
        System.out.println("EOL encountered.");
        break;
      case StreamTokenizer.TT_WORD:
        System.out.println("Word: " + inStream.sval);
        break;
      case StreamTokenizer.TT_NUMBER:
        System.out.println("Number: " + inStream.nval);
        break;
      default:
        System.out.println((char) token + " encountered.");
        if (token == '!')
          eof = true;
      }
    } while (!eof);
  }
}

   
  








Related examples in the same category

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