码迷,mamicode.com
首页 > 其他好文 > 详细

【笔记】读取properties文件

时间:2016-06-06 16:31:06      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:

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("燃油值班员"));
		

	}

}

 

【笔记】读取properties文件

标签:

原文地址:http://www.cnblogs.com/mybug/p/5563948.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!