zhyiwww
          用平實的筆,記錄編程路上的點點滴滴………
          posts - 536,comments - 394,trackbacks - 0

          The StreamTokenizer can be used for simple parsing of a Java source file into tokens. The tokenizer can be aware of Java-style comments and ignore them. It is also aware of Java quoting and escaping rules.

          				
          						try {
                  // Create the tokenizer to read from a file
                  FileReader rd = new FileReader("filename.java");
                  StreamTokenizer st = new StreamTokenizer(rd);
              
                  // Prepare the tokenizer for Java-style tokenizing rules
                  st.parseNumbers();
                  st.wordChars('_', '_');
                  st.eolIsSignificant(true);
              
                  // If whitespace is not to be discarded, make this call
                  st.ordinaryChars(0, ' ');
              
                  // These calls caused comments to be discarded
                  st.slashSlashComments(true);
                  st.slashStarComments(true);
              
                  // Parse the file
                  int token = st.nextToken();
                  while (token != StreamTokenizer.TT_EOF) {
                      token = st.nextToken();
                      switch (token) {
                      case StreamTokenizer.TT_NUMBER:
                          // A number was found; the value is in nval
                          double num = st.nval;
                          break;
                      case StreamTokenizer.TT_WORD:
                          // A word was found; the value is in sval
                          String word = st.sval;
                          break;
                      case '"':
                          // A double-quoted string was found; sval contains the contents
                          String dquoteVal = st.sval;
                          break;
                      case '\'':
                          // A single-quoted string was found; sval contains the contents
                          String squoteVal = st.sval;
                          break;
                      case StreamTokenizer.TT_EOL:
                          // End of line character found
                          break;
                      case StreamTokenizer.TT_EOF:
                          // End of file has been reached
                          break;
                      default:
                          // A regular character was found; the value is the token itself
                          char ch = (char)st.ttype;
                          break;
                      }
                  }
                  rd.close();
              } catch (IOException e) {
              }
          
          				
          		


          |----------------------------------------------------------------------------------------|
                                     版權聲明  版權所有 @zhyiwww
                      引用請注明來源 http://www.aygfsteel.com/zhyiwww   
          |----------------------------------------------------------------------------------------|
          posted on 2006-06-13 12:12 zhyiwww 閱讀(254) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 车致| 贺兰县| 隆昌县| 朝阳县| 尼木县| 犍为县| 雅安市| 建阳市| 靖宇县| 武鸣县| 海安县| 翁源县| 东丰县| 汝城县| 徐汇区| 石首市| 茂名市| 叶城县| 策勒县| 舟曲县| 绥阳县| 肃宁县| 新巴尔虎右旗| 二连浩特市| 盖州市| 怀来县| 沽源县| 迁安市| 淳安县| 双江| 乐业县| 甘南县| 磐安县| 乌苏市| 都江堰市| 宁津县| 科技| 阳新县| 贵德县| 常熟市| 上高县|