Java tutorial
import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; public class Main { public static void main(String[] args) { String destFile = "test.txt"; try (BufferedWriter bw = new BufferedWriter(new FileWriter(destFile))) { bw.append("test"); bw.newLine(); bw.append("test1"); bw.newLine(); bw.append("test2"); bw.newLine(); bw.append("test3"); bw.flush(); } catch (Exception e2) { e2.printStackTrace(); } } }