9

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

Eric
  • 1,031
  • 4
  • 14
  • 29

1 Answers1

1

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

Michael Lihs
  • 7,460
  • 17
  • 52
  • 85