/**
* 读取 .properties 配置文件
* @param propertiesUrl 配置文件的路径
* @return 配置文件中的key-value值
*/
public static Map getProperties(String propertiesUrl) {
Map resultMap = new HashMap();
Properties prop = new Properties();
try {
// 读取属性文件a.properties
InputStream in = new BufferedInputStream(new FileInputStream(propertiesUrl));
// 加载属性列表
prop.load(in);
Iterator 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;
}
使用方式
String path = System.getProperty("user.dir") + "\\conf\\303\\config.properties";
Map properties = TestUtil.getProperties(path);
System.out.println("哈哈哈" + properties.get("businessId"));
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)