Java StreamTokenizer .commentChar (int ch)
Syntax
StreamTokenizer.commentChar(int ch) has the following syntax.
public void commentChar(int ch)
Example
In the following code shows how to use StreamTokenizer.commentChar(int ch) method.
/* w w w . j ava2s .c om*/
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);
}
}
Home »
Java Tutorial »
java.io »
Java Tutorial »
java.io »