StringTokenizer t = new StringTokenizer("abcdefghi.abcde$fgh 8000");
String command = t.nextToken().toLowerCase();
我这样解析的时候出现
java.util.NoSuchElementException
at java.util.StringTokenizer.nextToken(StringTokenizer.java:232)

解决方案 »

  1.   

    没发现这样的问题NoSuchElementException - if there are no more tokens in this tokenizer's string.the default delimiter set, which is " \t\n\r\f": the space character, the tab character, the newline character, the carriage-return character, and the form-feed character. 这样的话可以得到两个token
    用空格分隔的你在这之前调用过nextToken吗,调用一次,处理位置会向前进一个token
      

  2.   

    楼上的,你用这个字符串试试看:"abcdefghi.abcde$fgh 8000",像"this is a test"这样的字符串我也没问题的.
      

  3.   

    .toLowerCase()
    we为什么要转换成小写。
    ^_^?
    标点符号,转有用吗?
    ^_^
      

  4.   

    import java.net.*;
    import java.io.*;
    import java.util.*;
    public class MgeClient {
      public MgeClient() {
      }
      public static void main(String[] args) throws Exception {
        if (args.length != 2) {
          System.out.println("用法:Client <主机名> <端口号>");
          return;
        }
        DataInputStream sin=new DataInputStream(System.in);
          System.out.print("you say:");
          String cmdStr=sin.readLine(); //读取用户输入的字符串
          StringTokenizer t = new StringTokenizer(cmdStr," ");
          System.out.println(t.countTokens());
      }}
    这样读入一个string为什么不行?就输入"abcdefghi.abcde$fgh 8000"这样一个字符串
      

  5.   

    JDK1.4以上的String类中增加了一个split方法