Home » Category » Java Essentials

Java Essentials: "\n" doesn't work on files?

300| Mon, 24 Sep 2007 18:39:00 GMT| manugarciaca| Comments (4)

I have a String that contains something like this:

Hello,\nmy name\nis Manuel.

When I do a System.out.println of that string it comes out like this:

Hello,

my name

is Manuel

However, when I redirect that to a file it comes out like this (I wrote ?but it comes out as a square):

Hello,簃y name篿s Manuel

What can I do to make it appear as it should in the file?

Keywords & Tags: doesn, work, files, java, essentials

URL: http://java.itags.org/java-essentials/14/
 
«« Prev - Next »» 4 helpful answers below.
If you're working on Windows you'll need "\r\n".The String: System.getProperty("line.separator") will work correctly on all platforms (as long as you stay on it).[url]http://java.sun.com/docs/books/tutorial/essential/system/properties.html[/url]

da_futta | Fri, 13 Jul 2007 20:01:00 GMT |

Instead of opening your file with Notepad, try to open it with WordPad.

jfbrierea | Fri, 13 Jul 2007 20:01:00 GMT |

Thanks a lot. I did the line.separator thing and works really well.

manugarciaca | Fri, 13 Jul 2007 20:01:00 GMT |

> Thanks a lot. I did the line.separator thing and> works really well.You're welcome.

da_futta | Fri, 13 Jul 2007 20:01:00 GMT |

Java Essentials Hot Answers

Java Essentials New questions

Java Essentials Related Categories