How to write multiple string property values ​​using the Create Configuration property?

I have a properties file with a property with the value List (separated by commas), how to write this property in several lines? (backslash after comma)?

I can't find anything about this, or at least about escaping from comma to backslash.

+78
java properties apache-commons-config
Jan 23 '12 at 17:28
source share
4 answers

If you mean the following; which just relies on a backslash + end of line. I just found this documented in: http://docs.oracle.com/javase/6/docs/api/java/util/Properties.html

primes = 2,\ 3,\ 5,\ 7,\ 11 
+121
Jan 23 2018-12-12T00:
source share

Check the User Guide for property files :

Special characters and escapes :

If you need a special character in a property such as a line, tab, or Unicode character, you can specify it with the same escaped notation used for Java strings. List delimiter ("," by default) can also be escaped:

key = This \n string \t contains \, escaped \\ characters \u0020

Backslashes are harder.

Lists and arrays :

You can specify a list of values ​​in the properties file using the same key on several lines:

 # chart colors colors.pie = #FF0000; colors.pie = #00FF00; colors.pie = #0000FF; 
+24
Jan 23 '12 at 20:17
source share

You need to combine the \n character inside the content and the line continuation escape ( \<eol> at the end of the line) to get a multi-line line property that will actually be represented in the properties file and in the return value:

 KEY1=first line\n\ second line\n\ last line KEY2=another key 

Not sure if the commons configuration can be configured to actually use this syntax for writing.

+9
Aug 15 '16 at 4:53 on
source share

Another option would be to use one of the property formats, which is designed to support multi-line values.

XML can handle multi-line properties well, but there is a lot of noise in it.

MProps: example format without much special formatting: https://github.com/mprops/mprops-java

0
Jun 05 '18 at 17:01
source share



All Articles