/**
* 读取properties 里面的数据
* @方法说明:
* @方法名称:getValue
* @param data key集合
* @param soure 文件名称
* @return
* @作者:zw
* @返回值:Map
*/
public static Map getValue(List data,String soure){
Map map = new HashMap();
if(data!= null && data.size()>0){
Properties prop = new Properties();
in = Object.class.getResourceAsStream("/"+soure);
try {
prop.load(in);
for (int i = 0; i < data.size(); i++) {
map.put(data.get(i), prop.getProperty(data.get(i)).trim());
}
} catch (IOException e) {
e.printStackTrace();
}
}
return map;
}
测试
你得 有个properties文件
public static void main(String args[]) {
//System.out.println(getParam1());
//System.out.println(getParam2());
List data = new ArrayList();
data.add("url");
data.add("password");
Map value = getValue(data,"sms.properties");
System.out.println(value.get("url"));
System.out.println(value.get("password"));
}
结果