⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 propertiesconfiguration.java

📁 银行项目为后台socket通信写的程序
💻 JAVA
字号:
/****************************************************************************
 * Package		: com.ecSolutions.ecAppServer.config
 * File			: PropertiesConfiguration.java
 * Create Date  : 2007-7-20
 * Author		: Steven Chen
 * 
 * Copyright(C) 2006 ecSolutions(shanghai) Co.,Limited.All Rights Reserved.
 *			
 ***************************************************************************/
package com.ecSolutions.ecAppServer.config;

import java.io.IOException;
import java.util.Properties;

import org.apache.log4j.Logger;

import com.ecSolutions.ecAppServer.Configuration;
import com.ecSolutions.ecAppServer.ecAppServerConfigException;
import com.ecSolutions.ecAppServer.util.Constants;
import com.ecSolutions.ecAppServer.util.FileUtil;


public class PropertiesConfiguration implements Configuration {
	
	private static PropertiesConfiguration instance = null;
	
	private Properties prop = null;
	
	private static Logger log = Logger.getLogger("PropertiesConfiguration");
	
	
	
	private PropertiesConfiguration() throws ecAppServerConfigException{
		try {
			prop = FileUtil.loadProperties(Constants.CONFIG_FILE);
		} catch (IOException e) {
			log.error(e.toString());
			throw new ecAppServerConfigException(e);
		}
	}
	
    public static synchronized PropertiesConfiguration getInstance() throws ecAppServerConfigException{
        if (instance==null)
            instance = new PropertiesConfiguration();
        return instance;
    }
	
	public String getString(String param) throws ecAppServerConfigException {
		String val = prop.getProperty(param);
		if (val == null) {
			throw new ecAppServerConfigException("Not found : " + param);
		}
		return val;
	}

	public String getString(String param, String defaultVal) {
		return prop.getProperty(param, defaultVal);
	}
	
	public int getInt(String param) throws ecAppServerConfigException {
		String val = prop.getProperty(param);
		if (val == null) {
			throw new ecAppServerConfigException("Not found : " + param);
		}

		try {
			return Integer.parseInt(val);
		} catch (Exception ex) {
			throw new ecAppServerConfigException("PropertiesConfiguration.getInt()", ex);
		}
	}

	public int getInt(String param, int defaultVal) {
		int retVal = defaultVal;
		try {
			retVal = getInt(param);
		} catch (Exception ex) {
		}
		return retVal;
	}

	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -