Я хочу заполнить HashMap
с помощью класса Properties
. Я хочу загрузить записи в файл .propeties
, а затем скопировать его в HashMap
.
Раньше я просто инициализировал HashMap
с помощью файла свойств, но теперь я уже определил HashMap
и хочу инициализировать его только в конструкторе.
Более ранний подход:
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);
Но теперь у меня это
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
}
}
Как мне назначить объект свойств HashMap
здесь?