我无法看到下面的代码有什么问题。没有时输出空值。为什么我的Java BufferedReader在文件开始和结束时读取空值?
输出:null This is one. This is two. This is three. This is four five six. seven? null
文件的内容:
This is one.
This is two.
This is three.
This is four
five
six.
seven?
任何帮助将不胜感激!
try (BufferedReader br = new BufferedReader(new FileReader(filename))) {
String cLine="";
while ((cLine = br.readLine()) != null) {
content+= cLine;
}
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(content);
显示如何初始化内容,可能设置为空 – 2013-02-28 20:19:48
此外,更喜欢使用['StringBuilder'](http://docs.oracle.com/javase/ 6/docs/api/java/lang/StringBuilder.html)重复连接字符串。 – 2013-02-28 20:23:24