Newer
Older
pgdsc / src / com / szpg / util / Configure.java
admin on 12 Jan 2018 1 KB 2018-01-12
package com.szpg.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

public class Configure {

//	private static Properties properties = new Properties();
	// 配置文件集合
	private static Map<String, Properties> pMap = new HashMap<String, Properties>();

	static {
		try {
			ClassLoader cl = Configure.class.getClassLoader();
			
			// 获取sys配置文件信息
			Properties sys = new Properties();
			InputStream sysIs = cl.getResourceAsStream("sys.properties");
			sys.load(sysIs);
			pMap.put("SYS", sys);
			
			// 获取ACUBL配置文件信息
			Properties bl = new Properties();
			InputStream blIs = cl.getResourceAsStream("ACUBL.properties");
			bl.load(blIs);
			pMap.put("ACUBL", bl);
			
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static String getProperty(String file, String key) {
		return pMap.get(file.toUpperCase()).getProperty(key);
	}
	
	public static String getProperty(String file, String key, String defaultValue) {
		String value =  pMap.get(file.toUpperCase()).getProperty(key);
		if (null == value) {
			return defaultValue;
		} else {
			return value;
		}
	}

	public static void main(String[] args) {
		System.out.println(Configure.getProperty("sys", "LOCALHOST.NODE"));
		System.out.println(Configure.getProperty("acubl", "YXL.ACU001.DCH01_Val"));
	}

}