首页 > 其他分享 >properties文件加载工具类

properties文件加载工具类

时间:2023-02-08 22:47:25浏览次数:45  
标签:文件 java Map properties util map Properties 加载

import java.util.HashMap;
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文件夹下

标签:文件,java,Map,properties,util,map,Properties,加载
From: https://www.cnblogs.com/lizhenfeng/p/17103592.html

相关文章