标签:
package com.bshinfo.el.userInfo.util; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; import java.util.Properties; public class SystemConfigUtil { private static SystemConfigUtil systemConfigUtil = null; private static Map<String, String> proMap = new HashMap<String, String>(); private SystemConfigUtil() { Properties pro = new Properties(); try { pro.load(new InputStreamReader(SystemConfigUtil.class.getClassLoader().getResourceAsStream("printgz.properties"), "UTF-8"));//默认根目录下 Enumeration e = pro.propertyNames(); while (e.hasMoreElements()) { String key = (String) e.nextElement(); String value = (String) pro.get(key); proMap.put(key, value); } } catch (IOException e) { e.printStackTrace(); } } public static SystemConfigUtil getInstance() { if (systemConfigUtil == null) { systemConfigUtil = new SystemConfigUtil(); } return null; } public static Map<String, String> getProMap() { return proMap; } public static void main(String[] args) { // 写一个main方法,来验证一下 SystemConfigUtil systemConfigUtil = SystemConfigUtil.getInstance(); SystemConfigUtil systemConfigUtil2 = SystemConfigUtil.getInstance(); System.out.println(systemConfigUtil == systemConfigUtil2); Map m1 = systemConfigUtil.getProMap(); Map m2 = systemConfigUtil2.getProMap(); System.out.println(m1 == m2); System.out.println(m1.get("test")); System.out.println(m1.get("燃油值班员")); } }
标签:
原文地址:http://www.cnblogs.com/mybug/p/5563948.html