Java BufferedWriter IOException "Too many open files"
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/4289447/java-too-many-open-files">Java Too Many Open Files</a>  </p>
</blockquote>



<p><strong>This is not a duplicate, the referred question is different, only the title is same, please read carefully</strong></p>



<p>This is my file write function</p>

<pre><code> 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);
            }
        }
    }
}
</code></pre>

<p>i have also seen <a href="http://stackoverflow.com/questions/2960427/java-bufferedwriter-close">this question</a> but it doesn't seem to help, if close is a blocking call then it shouldn't give this problem.</p>

<p>but when i call WriteLog function too frequently i.e. in a loop i get this error:</p>

<pre><code>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), 
</code></pre>

<p>After some specific number of calls, on every subsequent call i keep on getting this error and no more text is written in the file. Can anybody tell me the reason I am totally confused.</p>

<p>Thanks in advance</p>
