我试图从 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();
这可能是一些帮助:http://stackoverflow.com/questions/1388602/do-i-need-to-close-both-filereader-and-bufferedreader – NINCOMPOOP 2012-02-21 10:51:37
请不要使用DataInputStream来读取tex吨。不幸的是,这样的例子会被一次又一次地复制,所以你可以从你的例子中删除它。 http://vanillajava.blogspot.co.uk/2012/08/java-memes-which-refuse-to-die.html – 2013-01-31 00:11:33
不要使用rose india的代码。多少次错误或质量差的代码是令人惊讶的。 – 2013-07-20 13:46:01