import java.io.*; public class Whatever { /** * @param args */ public static void main(String[] args) { File target = new File("test.txt"); String lineToWrite = "a new line"; try { FileWriter writer = new FileWriter(target, true); // This opens the file in append mode writer.write(lineToWrite + "\n"); writer.close(); } catch (IOException e) { //Throw it as a runtimeexception to exit the program throw new RuntimeException(e); } } }