Writing to a temporary file in java
<p>I want to write to a temporary file in an append mode. I see that the file is created but the data from the Stringbuffer is not getting written to it. Can somebody tell me why? Please find below the code I have written, </p>

<pre><code>public static void writeToFile(String pFilename, StringBuffer sb)
        throws IOException {

    String property = "java.io.tmpdir";


    String tempDir = System.getProperty(property);

    File dir = new File(tempDir);
    File filename = File.createTempFile(pFilename, ".tmp", dir);
    FileWriter fileWriter = new FileWriter(filename.getName(), true);
    System.out.println(filename.getName());
    BufferedWriter bw = new BufferedWriter(fileWriter);
    bw.write(sb.toString());
    bw.close();
}
</code></pre>
