how to read property name with spaces in java

后端 未结 4 760
甜味超标
甜味超标 2020-12-18 20:04

I am trying to load all the property names present in the properties file using the below code:

for(Enumeration en = (Enumeration         


        
4条回答
  •  余生分开走
    2020-12-18 20:18

    It seems to be working fine for me; here is my code:

       Properties prop = new Properties();
       prop.setProperty("test1", "val1");
       prop.setProperty("test number 2", "val number 2");
       prop.setProperty("test 3", "val3");
       prop.setProperty("test #4", "val #4");
       for(Enumeration en = (Enumeration) prop.propertyNames();en.hasMoreElements();){
           String key = (String)en.nextElement();
           System.out.println("'" + key + "'='" + prop.getProperty(key) + "'");
       }
    

    And the output:

    'test 3'='val3'
    'test number 2'='val number 2'
    'test1'='val1'
    'test #4'='val #4'
    

    You can compare that to yours as far as setting it goes, as our displaying seems to be the same. If you don't see anything, add your full code, and I'll take a look

提交回复
热议问题