import java.util.HashMap;标签:文件,java,Map,properties,util,map,Properties,加载 From: https://www.cnblogs.com/lizhenfeng/p/17103592.html
import java.util.Map;
import java.util.Properties;
/**
* @author Administrator
*/
public class PropertiesUtils {
public static Map<String, String> load() {
Map<String, String> map = new HashMap<>(16);
try{
Properties properties = new Properties();
properties.load(PropertiesUtils.class.getResourceAsStream("xxx.properties"));
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
Object key = entry.getKey();
Object value = entry.getValue();
if(key!=null && value!=null){
map.put(key.toString(), value.toString());
}
}
} catch (Exception e){
e.printStackTrace();
}
return map;
}
}
文件路径在resource文件夹下