nextToken()是返回什么?
ttype里存储的是什么?
SteamTokenizer是怎样进行划分字符串的?
StreamTokennizer tokenizer = new StreamTokenizer(new InputStreamReader(System.in));
int ttype= tokenizer.nextToken();
if(ttype==tokenizer.TT_WORD||ttype =='\"'||ttype=='\'')
return .......;这段代码什么意思?

解决方案 »

  1.   

    public int nextToken()
                  throws IOException从此标记生成器的输入流中分析下一个标记。下一个标记的类型在 ttype 字段中返回。关于该标记的其他信息可能位于此标记生成器的 nval 字段或 sval 字段中。 
    此类的典型客户机首先建立语法表,然后循环调用 nextToken 来分析后续标记,直到返回 TT_EOF。 
    返回:
    ttype 字段的值。
    public class StreamTokenizerextends ObjectStreamTokenizer 类获取输入流并将其分析为“标记”,允许一次读取一个标记。分析过程由一个表和许多可以设置为各种状态的标志控制。该流的标记生成器可以识别标识符、数字、引用的字符串和各种注释样式。 从输入流读取的每个字节都被视为一个字符,范围在 '\u0000' 到 '\u00FF' 之间。字符值用于查找该字符的五个可能属性:空白、字母、数字、字符串引号 和注释字符。每个字符都可以有零个或多个这样的属性。 另外,一个实例还有四个标志。这些标志指示: 行结束符是作为标记返回,还是被视为仅用于分隔标记的空白。 
    是标识还是跳过 C 样式注释。 
    是标识还是跳过 C++ 样式注释。 
    是否将标识符的字符转换为小写字母。 
    典型的应用程序首先构造此类的一个实例,建立一个语法表,然后重复循环,调用该循环的每个迭代中的 nextToken 方法,直到返回值 TT_EOF。 --------------------
    摘录API,其实看一下StreamTokenizer的API就知道了.
      

  2.   

    1. nextToken() 即是读取并解析输入流字串中下一上符号。
    2. ttype即nextToken的返回值,代表解析到的下个符号的类型:数字字串或字符字串等.
    3.StreamToken对于字串的划分在其JavaDoc中说的很明确:
    The parsing process is controlled by a table and a number of flags that can be set to various states. The stream tokenizer can recognize identifiers, numbers, quoted strings, and various comment styles. Each byte read from the input stream is regarded as a character in the range '\u0000' through '\u00FF'. The character value is used to look up five possible attributes of the character: white space, alphabetic, numeric, string quote, and comment character. Each character can have zero or more of these attributes. In addition, an instance has four flags. These flags indicate: Whether line terminators are to be returned as tokens or treated as white space that merely separates tokens. 
    Whether C-style comments are to be recognized and skipped. 
    Whether C++-style comments are to be recognized and skipped. 
    Whether the characters of identifiers are converted to lowercase. 
    A typical application first constructs an instance of this class, sets up the syntax tables, and then repeatedly loops calling the nextToken method in each iteration of the loop until it returns the value TT_EOF. 
    --------------------
    我的E文不是很好,我的理解是,他有个一般的规则。另外,应当是可以通过它提供的方式定制其行为的。4. 关于这段代码的意思是:
    (1).首先以标准的输入流作为本次解析源。例如:你由控制台录入一个字串后,程序开始读取并开始解析。
    (2).if(ttype==tokenizer.TT_WORD||ttype =='\"'||ttype=='\'')即果检查当前解析到的字串是不是一个单词或者是一个双引号或者是单引号,则 return .....;
      

  3.   

    有没有范例程序给举一个也行,我看API了,还是不会使用这个类
      

  4.   

    StringTokenizer st=new StringTokenizer(字符串,"分隔符")
    如原字符串為:2123456/234234234
    要取出前后兩端的字符串
    可以這樣:
    String s="2123456/234234234";
    StringTokenizer st=new StringTokenizer(s,"/");
    String[] t=new String[2];
    int i=0;
    while(st.hasMoreTokens())
    {
       t[i]=st.nextToken();
       i++;
    }
    這樣就把分析出來的字符串放到數組中去了
    端刀引路,后面的還得兄弟自己去發展了!
      

  5.   

    感觉二楼已经解释的很好了,不知道楼主想拿StreamTokenizer用来做什么咧?
      

  6.   

    这个类基本上没有什么使用价值了
    直接使用Split更好