package test.c11;
import java.io.*;
public class FileStreamTokenizerTest {
?public static void main(String[] args) {
??try{
//???BufferedReader br = new BufferedReader(
//????new InputStreamReader(new FileInputStream("c:\\2.txt")));
//???StreamTokenizer st = new StreamTokenizer(br);
???StreamTokenizer st = new StreamTokenizer(
?????new StringReader("abc.a.azqbchi;na2.bmmdchina3.1223a.0ckyychina4.dwmjchina5.ethchina6.wmjchina"));
???st.quoteChar('.');
//???st.ordinaryChars('a','c');
//???st.whitespaceChars('a','c');
//???st.wordChars('a','c');
//???st.resetSyntax();
???while(st.nextToken()!=StreamTokenizer.TT_EOF){
????if (st.ttype==StreamTokenizer.TT_NUMBER){
?????System.out.println("this NUMBER value is : "+st.nval);
????}else if(st.ttype==StreamTokenizer.TT_WORD){
?????System.out.println("this WORD value is : "+st.sval);
????}else{
?????System.out.println("type is : "+st.ttype+" the value is :"+st.sval);
????}
???}
??}catch(FileNotFoundException e){
???e.printStackTrace();
??}catch(IOException e){
???e.printStackTrace();
??}
?}
}
輸出如下:
this WORD value is : abc
type is : 46 the value is :a
this WORD value is : azqbchi
type is : 59 the value is :null
this WORD value is : na2
type is : 46 the value is :bmmdchina3
this NUMBER value is : 1223.0
this WORD value is : a
type is : 46 the value is :0ckyychina4
this WORD value is : dwmjchina5
type is : 46 the value is :ethchina6
this WORD value is : wmjchina
==========================
有一點不明白:
na2和ethchina6為什么一個類型是WORD(-3),一個類型是46呢?