I'm trying to print a multiple-line String into a PrintWriter, but it doesn't recognizes the different lines.
I have this String: "2\n0 0 1 string1\n0 2 1 string2".
The text I expected to have into the file was:
2
0 0 1 string1
0 2 1 string2
but it actually is:
20 0 1 string10 2 1string2
My code is:
public void save(String str){
try{
PrintWriter out = new PrintWriter("file.txt");
out.println(str);
out.close();
System.out.print(str);
}catch(Exception e){System.out.println(e);}
}
It's printed OK in the console.
I'm using BlueJ to code. My OS is W7 and I just opened the file with notepad.
SOLVED!
Using "\r\n" instead of just "\n" works properly!