import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; public class Example { public static void main(String[] args) { String text = "This is an example text"; try (BufferedWriter writer = new BufferedWriter(new FileWriter("example.txt"))) { writer.write(text); writer.newLine(); writer.write("This text is on a new line"); } catch (IOException e) { e.printStackTrace(); } } }In the above example, we create a new BufferedWriter object to write the text to the file. The newLine() method is used to create a new line after writing the first line. This creates a newline character that is platform-independent. The BufferedWriter class is part of the Java Standard Library.