package cn.com.ctop.common.utils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.InputStream; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Properties; public class PropertiesUtils { private static final Logger log = LoggerFactory.getLogger(PropertiesUtils.class); private static Map cache = new HashMap(); public static String getConfig(String key) { return getValue("kuaishou_config", key); } public static String getValue(String name, String key) { try { String cacheValue = (String) cache.get(name + key); if (cacheValue != null) { return cacheValue; } Properties props = new Properties(); InputStream in = PropertiesUtils.class.getResourceAsStream("/" + name + ".properties"); props.load(in); String value = props.getProperty(key); cache.put(name + key, value); props.clone(); in.close(); return value; } catch (Exception e) { log.error("PropertiesUtil getCacheValue Error", e); } return null; } public static Map getMap(String name) { try { Properties props = new Properties(); InputStream in = PropertiesUtils.class.getResourceAsStream("/" + name + ".properties"); props.load(in); Iterator it = props.keySet().iterator(); Map map = new HashMap(); while (it.hasNext()) { String key = it.next().toString(); String value = props.getProperty(key); map.put(key, value); } props.clone(); in.close(); return map; } catch (Exception e) { log.error("PropertiesUtil getMap Error", e); } return null; } }