Possible Duplicate:
Java Too Many Open Files的Java的BufferedWriter IOException異常「打開的文件太多」
這不是重複,所提到的問題是不同的,只有標題是相同的,請仔細閱讀
這是我的文件寫功能
public static void WriteLog(String LogLine) {
String filePath = CommonClass.ReadPropertiesFile("LogFilepath");
BufferedWriter out = null;
try {
// Create file
FileWriter fstream = new FileWriter(filePath, true);
out = new BufferedWriter(fstream);
out.write(LogLine + "\r\n");
} catch (Exception e) {//Catch exception if any
System.err.println("Error: " + e.getMessage());
} finally {
//Close the output stream
if (out != null) {
try {
out.write("Closing stream\r\n");
out.close();
} catch (IOException ex) {
System.err.println("Error Closing stream: " + ex.getMessage());
Logger.getLogger(LogWritter.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
我也看到this question但它似乎並沒有幫助,如果近是一個阻塞調用,然後它不應該給這個問題。
但是當我打電話WRITELOG功能在一個循環過於頻繁,即我得到這個錯誤:
Error: (No such file or directory)
Could not load properties File, Exception: (Too many open files),
Error: (No such file or directory)
Could not load properties File, Exception: (Too many open files),
調用某個特定數量後,在隨後每次調用我不斷獲取此錯誤並沒有更多的文字寫在文件中。任何人都可以告訴我我完全困惑的原因。
在此先感謝
這可能是相關的:http://stackoverflow.com/questions/4289447/java-too-many-open-files –
你有太多打開的文件。該進程在進程啓動時指定了一些最大數量的打開文件,並且您已超出該限制。可能你沒有在某處關閉文件。 –
@熱舔:多數民衆贊成我想問,我在哪裏錯過關閉文件,我想我可以讀取例外說「太多打開的文件」我想知道文件沒有被關閉的地獄 – shabby