简体   繁体   中英

Properties file escape a value

I've looking through How to escape the equals sign in properties files but didn't find my answer.

I have a Java Properties File that includes sets such as:

SOME_KEY = SOME_VALUE

This is normal. However, some of the values actually contain escape/control characters, such as URL's. This properties file is to be hand edited by a user on a rare occasion. I want the user to be able to simply paste in a URL and not worry about special rules, etc.

So I have this showing in my file now:

SOME_KEY = http://www.example.com/something.asp?some=

where some= is the base of dynamic URL where something after the = will cause the URL to respond differently.

From reading http://docs.oracle.com/javase/6/docs/api/java/util/Properties.html it doesn't seem to make mention of needing to escape any escape/control characters after the first unescaped = or : is encountered, but I need/want to make sure.

I know that if my KEY had one of those characters present, then it would have to be escaped otherwise it'd be misread... such as:

SOME\=KEY = SOME_VALUE

Would make for a literal SOME=KEY as the key value.

In this above situation, excluding the obvious escaping of the KEY , is it necessary to hand-escape the values?

After the first = without escape, no.

If you use eclipse, you might want install the JBoss Tools Properties Editor . You not need to worry about escaping values ​​manually as you mention SOME=KEY or Unicode. However, the pluging escapes the characters to avoid reading and coding problems.

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

http://www.jboss.org/tools

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM