The following example illustrates how the String.split method can be used to break up a string into its basic tokens:
String[] result = "this is a line read from txt file".split("\\s");
for (int x=0; x<result.length; x++)
System.out.println(result[x]);
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
String[] result = "123 321 -1 555".split("\\s");
for (int x=0; x<result.length; x++){
int value= -999999; //default
try{
value= Integer.parseInt(result[x]);
}catch (Exception e){}
System.out.println(value);
}
参考资料:http://java.sun.com/j2se/1.4.2/docs/api/java/util/StringTokenizer.html
本回答被提问者采纳