String info ="good good study day day up";
StringReader stringReader = new StringReader(info); //流标记器,处理标记,例如空格 StreamTokenizer st = new StreamTokenizer(stringReader);
例子
import java.io.*; public class file { public static void main(String[] args) {
stringReader();
} private static void stringReader() {
String info ="good good study day day up";
StringReader stringReader = new StringReader(info);
//流标记器,处理标记,例如空格
StreamTokenizer st = new StreamTokenizer(stringReader);
int count = 0;
while (st.ttype != StreamTokenizer.TT_EOF){
try {
if(st.nextToken() == StreamTokenizer.TT_WORD){
count ++ ;
}
} catch (IOException e) {
e.printStackTrace();
}
}
stringReader.close();
System.out.println("count="+count);
}
}