13

I'm using Java Property files and would like to have a newline character put into a value (used as the contents of a message to the user), so that this output contains a new line.

I tried putting it in as a \\n (as I have to escape the backslash character), but I just end up with a message with \n written in it.

ie.

message=Dear Foo,\\n\\nThank you for signing up for Bar.

gives:

Dear Foo,\n\nThank you for signing up for Bar.

I want:

Dear Foo,

Thank you for signing up for Bar.

How can I fix this? Thanks!

iank
  • 800
  • 3
  • 10
  • 32

2 Answers2

18

Simply use \n for this purpose

You are escaping the escape character using \\ hence you are getting \n printed

Nitin Chhajer
  • 2,299
  • 1
  • 24
  • 35
  • I did that because I was under the impression that Properties will remove the \ character. I wanted it to be preserved for when it goes into the string. – iank Jun 26 '12 at 19:38
3

This should do it:

message=Dear Foo,\nThank you for signing up for Bar.
GETah
  • 20,922
  • 7
  • 61
  • 103