Java: 初涉StreamTokenizer类

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呢?

posted on 2007-08-02 17:21 心砚 阅读(1689) 评论(0)  编辑  收藏 所属分类: Java


只有注册用户登录后才能发表评论。


网站导航:
 
<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

导航

统计

常用链接

留言簿(2)

随笔分类

文章分类

文章档案

Forum

搜索

最新评论

阅读排行榜

评论排行榜