访问.properties文件的单例类

package com.adc.da.util.utils;

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

public class ProWebPathFactory {
        
    private static ProWebPathFactory webPath = null;
    private Properties properties = new Properties();
        
    private ProWebPathFactory() {
         try {
            InputStream inputStream = this.getClass().getResourceAsStream("/properties/webPath.properties");
            properties.load(inputStream);
            if (inputStream != null){
                inputStream.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 单例静态工厂方法
     * yangyang
     * 2017-12-21
     */
    public static ProWebPathFactory getInstance() {
        if (webPath == null) {
            webPath = new ProWebPathFactory();
        }
        return webPath;
    }

  
    /**
     * 读取配置信息key - value
     * yangyang
     * 2017-12-21
     */
    public String getConfig(String key) {
        return properties.getProperty(key);
    }

}

 

posted @ 2017-12-26 17:10  DaMie  阅读(284)  评论(0)    收藏  举报