java读取自定义的.properties 配置文件 中的key

Wesley131437 阅读
文章目录
/**
* 读取 .properties 配置文件
* @param propertiesUrl 配置文件的路径
* @return 配置文件中的key-value值
*/
public static Map<String, String> getProperties(String propertiesUrl) {
Map<String, String> resultMap = new HashMap<String, String>();
Properties prop = new Properties();
try {
// 读取属性文件a.properties
InputStream in = new BufferedInputStream(new FileInputStream(propertiesUrl));
// 加载属性列表
prop.load(in);
Iterator<String> it = prop.stringPropertyNames().iterator();
while (it.hasNext()) {
String key = it.next();
resultMap.put(key, prop.getProperty(key));
System.out.println("key: "+key+", value: "+prop.getProperty(key));
}
in.close();
} catch (Exception e) {
System.out.println(e);
}
return resultMap;
}
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册⭐️ Admin快速开发: https://show.cool-admin.com/
赞 0⭐️ 官方文档: https://cool-js.com
赞 0⭐️ chatgpt在线体验: https://cool-js.com/ai/chat-vip/index.html?r=helloworld
赞 0