I have a String that contains for example “Name: Foo \n Date: 12/13/11 \n”
When I do BufferedWriter.write(String) to a text file it actually outputs the \n is there anyway to do a replace on \n to something that when written to a text file will signify a line break?
Here is sample code.
String input = "Name: adfasd \n AN: asdfasdf \n";
Writer textOutput = null;
File file = new File("write.txt");
textOutput = new BufferedWriter(new FileWriter(file));
textOutput.write( input );
textOutput.close();
The output would be
Windows uses CR+LF line endings as opposed to LF endings. You should be able to use
\r\nto get your desired result.Wikipedia has an article about newlines if you want to know more.