Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I put a \n into a property file's value?

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!

like image 207
iank Avatar asked Jun 26 '12 19:06

iank


People also ask

How do you insert a line break in properties file?

for long paragraph, just use \ at the end of the line.

How do you write multiple lines in properties file?

A property value can span several lines if each line is terminated by a backslash ('\') character. For example: targetCities=\

How do you line break a string?

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.

How do you write key value pairs in properties file?

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.


1 Answers

Simply use \n for this purpose

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

like image 71
Nitin Chhajer Avatar answered Sep 20 '22 13:09

Nitin Chhajer