I want to support property file format like below (allow quotes surround the value):
key1=value1
key2="value2"
key3='value'
My question is does Java Properties class implementation handles double/single quoted values like above? I mean auto-removing quotes.
Actually I tried it's not, just want to confirm here. So I have to remove quotes myself.
EDIT:
I had a code below for my simple case:
String path = "/tmp/my.properties";
Properties p = new Properties();
p.load(new FileInputStream(new File(path)));
String v = p.getProperty("key2");
if((v.startsWith("\"") && v.endsWith("\"")) ||
(v.startsWith("\'") && v.endsWith("\'"))) {
v = v.substring(1, v.length()-1);
}
Any recommendation on best practice to handle this?
Thanks
A single quote itself must be escaped by using two single quotes ('').
Escaping double quotes in Java String If we try to add double quotes inside a String, we will get a compile-time error. To avoid this, we just need to add a backslash (/) before the double quote character. In this example, we want to print double quotes around the words “Steve” and “Java”. That's it!
Use char(34) to represent double quotes. Java can easily represent ASCII symbols using the char type. 34 is the ASCII code for the " symbol, so write char(34) to display " without using its special meaning.
They are the same thing In JavaScript, a string is a sequence of characters enclosed in single or double quotes. The choice of quoting style is up to the programmer, and either style has no special semantics over the other.
To remove quotes, load the property file with your own extension of ResourceBundle
which overrides handleGetObject
.
See also:
http://docs.oracle.com/javase/6/docs/api/java/util/Properties.html http://docs.oracle.com/javase/6/docs/api/java/util/ResourceBundle.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With