java - Populating a HashMap with entries from a properties file -


i want populate hashmap using properties class. want load entries in .propeties file , copy hashmap.

earlier, used initialize hashmap properties file, have defined hashmap , want initialize in constructor only.

earlier approach:

properties properties = new properties(); try { properties.load(classname.class.getresourceasstream("resume.properties")); } catch (exception e) {  } hashmap<string, string> mymap= new hashmap<string, string>((map) properties); 

but now, have this

public class classname { hashmap<string,integer> mymap = new hashmap<string, integer>();  public classname(){      properties properties = new properties();     try {       properties.load(classname.class.getresourceasstream("resume.properties"));     }     catch (exception e) {      }     mymap = properties;     //the above line gives error } } 

how assign properties object hashmap here ?

if understand correctly, each value in properties string represents integer. code this:

for (string key : properties.stringpropertynames()) {     string value = properties.getproperty(key);     mymap.put(key, integer.valueof(value)); } 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -