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!
for long paragraph, just use \ at the end of the line.
A property value can span several lines if each line is terminated by a backslash ('\') character. For example: targetCities=\
Adding Newline Characters in a String In Windows, a new line is denoted using “\r\n”, sometimes called a Carriage Return and Line Feed, or CRLF. Adding a new line in Java is as simple as including “\n” , “\r”, or “\r\n” at the end of our string.
getProperty(key) , we will fetch the value from the file. The same way, we can use prop. setProperty(Key, Value) to write data to . properties file.
Simply use \n
for this purpose
You are escaping the escape character using \\
hence you are getting \n
printed
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With