private Reader input; private void readNextToken() { StringBuffer buf = new StringBuffer();
boolean endReached = false;
int in = 0; try { // Read from the stream, until a letter occurs in = input.read();
char ch = (char) in; while ((in != -1) && Character.isWhitespace(ch)) {
in = input.read();
ch = (char) in;
} if (in != -1)
buf.append(ch); // Read from the stream, util a non-letter occurs while ((in != -1) && !Character.isWhitespace(ch)) { in = input.read();
ch = (char) in; if (!Character.isWhitespace(ch))
buf.append(ch); }
} catch (Exception e) {
endReached = true; } if (in == -1)
endReached = true; if (endReached) { // If the stream ended with a non-empty token, this is the last
// token, otherwise there is no more token. if (buf.length() > 0)
currentToken = buf.toString();
else
currentToken = null; return;
} else { // if the end of the stream has not been reached yet, simply store
// the extracted token.
currentToken = buf.toString();
return;
} }把一篇以空格作为标记分好词语的文本读取到字符流input中,然后想把各个词语从字符流中读出来,比如:
“中国 人民 英雄 纪念碑”。
目前只能处理英文,不知道处理中文程序要怎么改?
谢谢!!
用split(" ");应该很容易切开喵~~~`