【发布时间】:2012-03-11 16:22:21
【问题描述】:
我正在尝试一个示例
http://www.roseindia.net/java/beginners/java-read-file-line-by-line.shtml
在示例中,BufferReader 未关闭是否需要关闭BufferReader?请解释一下。
FileInputStream fstream = new FileInputStream("textfile.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
// Print the content on the console
System.out.println (strLine);
}
//Close the input stream
in.close();
【问题讨论】:
-
请不要使用 DataInputStream 读取文本。不幸的是,像这样的示例会一次又一次地被复制,因此您可以将其从示例中删除。 vanillajava.blogspot.co.uk/2012/08/…
-
不要使用来自印度玫瑰的代码。令人惊讶的是,它经常出现错误或质量差的代码。
标签: java