/** Test.java */ import java.io.*; public class Test { public static void main (String args[]) { BufferedWriter bw = null; try { bw = new BufferedWriter(new FileWriter("test.txt", true)); bw.newLine(); bw.write("This is cool."); bw.newLine(); bw.flush(); } catch (IOException ioe) { ioe.printStackTrace(); } finally { // always close the file if (bw != null) try { bw.close(); } catch (IOException ioe2) { // just ignore it } } // end try/catch/finally } }