我有一个可以从文本文件中读取的 InputStream。我注意到输入流不是从空白的下一行读取的。
示例文本文件:
[This is
A test file
Here.]
代码:
while ((str = br.readLine())!= null) {
System.out.println(str);
}
一些文本文件之间会有多条分隔线。如何让输入流接受断行?
从示例文本文件中可以看出,“[This is”后跟一个空行,然后是“A test file”。如何读取两组字符串之间的空行? (那是我对换行/断线的定义)
最佳答案
你是什么意思?
while ((str = br.readLine())!= null && str.trim().length()>0) {
System.out.println(str);
}
这会为您提供所有非空行。
关于java - 读取下一行 InputStream Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5792433/