获取配置文件的工具类

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
/**
 * 读取配置文件
 * @author zhangrujing
 *
 */
public enum Config {

    INSTANCE;
    
    private volatile Properties configuration = new Properties();
    
    public void init() {
        getConfiguration("system-config");
    }
    
    private void getConfiguration(String nodeName) {
        InputStream is = this.getClass().getResourceAsStream("/" + nodeName + ".properties");
        if (is != null) {
            try {
                this.configuration.clear();
                this.configuration.load(is);
            } catch (IOException e) {
            } finally {
                try {
                    is.close();
                } catch (Throwable t) {}
            }
        }
    }
    
    public String getConfigValue(String key) {
          return this.configuration.getProperty(key);
    }
    
}

 

求大神指导如何读取多个配置文件

posted @ 2015-01-25 11:09  IT小怪兽  阅读(185)  评论(0编辑  收藏  举报