import java.io.FileWriter; import java.io.BufferedWriter; import java.io.IOException; public class FileWriteExample { public static void main(String[] args) { try (BufferedWriter writer = new BufferedWriter(new FileWriter("example.txt", true))) { writer.write("This is a new line of text."); writer.newLine(); // Adds a newline System.out.println("Text written to the file."); } catch (IOException e) { System.out.println("An error occurred: " + e.getMessage()); } } }