I want to write to a temporary file in add mode. I see that the file is created, but the data from Stringbuffer is not written to it. Can someone tell me why? Below you will find the code I wrote,
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(); }
source share