the*_*tna 5 java bufferedreader
来自javadoc
public String readLine()
throws IOException
Read a line of text. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed.
Run Code Online (Sandbox Code Playgroud)
我有以下类型的文字:
Now the earth was formless and empty. Darkness was on the surface
of the deep. God's Spirit was hovering over the surface
of the waters.
Run Code Online (Sandbox Code Playgroud)
我正在阅读以下内容:
while(buffer.readline() != null){
}
Run Code Online (Sandbox Code Playgroud)
但是,问题是它正在考虑换行前的字符串行.但是我想在字符串结束时考虑行..我该怎么办?
您可以一次读取一个字符,并将数据复制到StringBuilder
Reader reader = ...;
StringBuilder sb = new StringBuilder();
int ch;
while((ch = reader.read()) >= 0) {
if(ch == '.') break;
sb.append((char) ch);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5935 次 |
| 最近记录: |