1 /** 2 * 读取 .properties 配置文件 3 * @param propertiesUrl 配置文件的路径 4 * @return 配置文件中的key-value值 5 */ 6 public static Map<String, String> getProperties(String propertiesUrl) { 7 Map<String, String> resultMap = new HashMap<String, String>(); 8 Properties prop = new Properties(); 9 try { 10 // 读取属性文件a.properties 11 InputStream in = new BufferedInputStream(new FileInputStream(propertiesUrl)); 12 // 加载属性列表 13 prop.load(in); 14 Iterator<String> it = prop.stringPropertyNames().iterator(); 15 while (it.hasNext()) { 16 String key = it.next(); 17 resultMap.put(key, prop.getProperty(key)); 18 System.out.println("key: "+key+", value: "+prop.getProperty(key)); 19 } 20 in.close(); 21 } catch (Exception e) { 22 System.out.println(e); 23 } 24 return resultMap; 25 }
java读取自定义的.properties 配置文件 中的key
Wesley13
2021-10-11
1348 1 0
点赞
收藏
评论区
加载中...