java 读取properties文件 ---封装组件

来源:互联网 发布:vb与vs的区别 编辑:程序博客网 时间:2024/04/30 08:50
/** * 读取properties 里面的数据 * @方法说明: * @方法名称:getValue * @param data key集合 * @param soure 文件名称 * @return * @作者:zw * @返回值:Map<String,Object> */public static Map<String, Object> getValue(List<String> data,String soure){Map<String, Object> map = new HashMap<String, Object>();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<String> data = new ArrayList<String>();data.add("url");data.add("password");Map<String, Object> value = getValue(data,"sms.properties");System.out.println(value.get("url"));System.out.println(value.get("password"));}

结果


0 0
原创粉丝点击