package com.bsteel.util; import java.text.MessageFormat; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Properties; /** * 读取property文件 * * @author WJ * */ public class PropertyUtil { private static Map<String, String> map = null; private static void loadFile() { map = new HashMap<>(); try { Properties p = new Properties(); p.load(PropertyUtil.class.getClassLoader().getResourceAsStream("bsteel.properties")); Iterator it = p.keySet().iterator(); while (it.hasNext()) { String key = (String) it.next(); String value = p.getProperty(key); map.put(key, value); } } catch (Exception e) { e.printStackTrace(); } } public static String getValue(String str) { if (map == null) { loadFile(); } return (String) map.get(str); } public static void main(String[] args) { System.out.println(MessageFormat.format(getValue("fdfs_upload_url"), "aaa", "bbb")); System.out.println(getValue("fdfs_upload_url")); } }
PropertyUtil , 增加 [ bsp1.0]
最新推荐文章于 2023-03-20 22:01:31 发布