我想使用Properties类填充HashMap.我想加载.propeties文件中的条目,然后将其复制到HashMap中.
此前,我曾经使用属性文件初始化HashMap,但是现在我已经定义了HashMap,并希望仅在构造函数中初始化它.
早期方法:
Properties properties = new Properties();
try {
properties.load(ClassName.class.getResourceAsStream("resume.properties"));
}
catch (Exception e) {
}
HashMap mymap= new HashMap((Map) properties);
但现在,我有这个
public class ClassName {
HashMap mymap = new HashMap();
public ClassName(){
Properties properties = new Properties();
try {
properties.load(ClassName.class.getResourceAsStream("resume.properties"));
}
catch (Exception e) {
}
mymap = properties;
//The above line gives error
}
}
在这里如何将属性对象分配给HashMap?