Avoiding Equals in Property Files

How can I avoid the equal sign ( = ) in Java property files? I would like to add something like this to the file:

 table.whereclause=where id=100 
+78
java properties escaping
Mar 09 '10 at 6:00
source share
8 answers

Also, refer to the download (reader) from the Property class in javadoc

The documentation for the load(Reader reader) method says:

The key contains all characters in a line starting with the first non-white space and before, but not including, the first unescaped '=' , ':' or a space character except for the line terminator. All of these key completion characters can be included in the key, avoiding them with the previous character backslash; eg,

 \:\= 

will be the two-character key ":=". Line-terminating characters can be including the use of \r and \n escape sequences. Any empty space after the key is skipped; if the first non-white space after the '=' or ':' key is ignored, any space characters after are also skipped. All other characters on the line become part of the associated line of the element; if there are no remaining characters, element is the empty string "" . once the raw character sequences constituting the key and the element are the identified transition processing as described above.

Hope this helps.

+78
Mar 09 '10 at 9:23
source share

In your specific example, you do not need to avoid equals - you only need to run away from it if it is part of the key. The properties file format will handle all characters after the first unshielded value becomes part of the value.

+78
Jul 15 '13 at 19:45
source share

The default equivalent character in Java is '\'.
However, the Java properties file has the format key = value, it should take into account everything after the first value equal.

+21
Mar 09 '10 at 6:08
source share

The best way to avoid such problems is to create software properties and then store them. For example, using this code:

 java.util.Properties props = new java.util.Properties(); props.setProperty("table.whereclause", "where id=100"); props.store(System.out, null); 

This will be output to System.out from a properly shielded version.

In my case, the output was:

 #Mon Aug 12 13:50:56 EEST 2013 table.whereclause=where id\=100 

As you can see, this is an easy way to generate the contents of .properties files that guarantee correctness. And you can add as many properties as you want.

+16
Aug 12 '13 at 10:52
source share

In my case, the two leading "\\" work fine for me.

For example: if your word contains the character "#" (for example, aa # 100, you can avoid it with the two leading '\\'

  key= aa\\#100 
+5
Nov 19. '15 at 15:36
source share

You can look here. Can a key in a Java property contain an empty character?

for output equal to '=' \ u003d

table.whereclause = where id = 100

: value [table.whereclause]: [where id = 100]

table.whereclause \ u003dwhere id = 100

: value [table.whereclause = where]: [id = 100]

table.whereclause \ u003dwhere \ u0020id \ u003d100

: value [table.whereclause = where id = 100]: []

+2
Jun 14 2018-12-12T00:
source share

In Spring or Spring, the application.properties boot file allows you to escape special characters here;

table.whereclause = where id '\ =' 100

0
Jun 18 '19 at 13:26
source share

I managed to enter the values โ€‹โ€‹inside the character:

 db_user="postgresql" db_passwd="this,is,my,password" 
-one
Jan 27 '16 at 15:21
source share



All Articles