Why I am getting OutOfMemory Exception?
<p>I am getting OutOfMemory Exception. Why? I am using this code for logging. Does this approach correct?
Exceptions and closing of streams are handled in parent methods.</p>

<pre><code>private static void writeToFile(File file, FileWriter out, String message) throws IOException {
    if (file.exists() &amp;&amp; file.isFile()) {
        if ((file.length() + message.getBytes().length) &lt;= FILE_MAX_SIZE_B) {
            out.write(message);
        } else {
            int cutLenght = (int) (file.length() + message.getBytes().length - FILE_MAX_SIZE_B);

            FileInputStream fileInputStream = new FileInputStream(file);
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fileInputStream));
            char[] buf = new char[1024];
            int numRead = 0;
            StringBuffer text = new StringBuffer(1000);
            while ((numRead=bufferedReader.read(buf)) != -1) {
                text.append(buf,0,numRead);
            }
            String result = new String(text).substring(cutLenght);
            result += message;
            FileWriter fileWriter = new FileWriter(file, appendToFile);
            writeToFile(file, fileWriter, result);
            bufferedReader.close();
        }
    }
}
</code></pre>

<p>EDIT:</p>

<p>I am using this method for writting my logs in file. So for example in one second I can call 10 logs. I am getting error on lines:</p>

<pre><code>while ((numRead=bufferedReader.read(buf)) != -1) {
                text.append(buf,0,numRead);
            }
</code></pre>
