Java Properties class implementation handles double/single quoted values?

13,284

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

Share:
13,284
Eric
Author by

Eric

Updated on June 04, 2022

Comments

  • Eric
    Eric almost 2 years

    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
    Eric about 11 years
    My case is simple, just one property file. No resource bundle stuff