首页 > 其他 > 详细

获取配置文件的工具类

时间:2015-01-25 12:23:37      阅读:193      评论:0      收藏:0      [点我收藏+]

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);
    }
    
}

 

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

获取配置文件的工具类

原文:http://www.cnblogs.com/IT-Monster/p/4247939.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!