I am trying to output a multi-line string to a file using FileWriter. How can I make it recognize the lines and automatically use “output.newLine”?
Example String
static String test = "This \n" + "is \n" + "a \n" + "sample \n" + "string."
public static void testMethod (String test){
FileWriter fileWriter = new FileWriter ("output.txt", true)
BufferedWriter bufferedWriter = new BufferedWriter (fileWriter);
bufferedWriter.write (test);
bufferedWriter.close ();
}
Use
text.split("\n")to create multiple lines and write them separately.