Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read .properties file in java with new line characters in values

I defined a .properties file with properties like this

A=Hello World this is a dummy text

B=Bye Bye World I am leaving to mars

I am able to read it properly after loading resource from input stream and display them good.

Now i want to define these properties like this

A= Hello World 
   this is a 
   dummy text

B= Bye Bye World 
   I am leaving to 
   mars

However it don't load it as expected

A as Hello World

and

B as Bye Bye World.

Do i have to go by myself defining a regex and read this and fill it in a map.

Or is there any way default available in Properties.java?

like image 353
Rohit Sharma Avatar asked Feb 19 '23 11:02

Rohit Sharma


1 Answers

You need to add a \n and then end the line with the "continuation" character: \

A=Hello World\n \
this is a\n \
dummy text

Note that leading whitespace is trimmed when loading the Properties file. So you need to add that to the end of the previous line if you need indented lines:

A=Hello World\n   \
this is a\n    \
dummy text
like image 107
a_horse_with_no_name Avatar answered Apr 07 '23 17:04

a_horse_with_no_name