临窗旋墨的博客       临窗旋墨的导航

工具类

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

/**
 *  1 读取src下的配置文件
 * 工具类
 */
public class Util {
    public Util() {
    }


    public static Properties prop = null;
    
    private static final String FILENAME = "constant.properties";
    
    public static Properties getPara() {

        prop = new Properties();
        try {
            InputStream is = Util.class.getClassLoader().getResourceAsStream(FILENAME);
            prop.load(is);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return prop;
    }
    
    /**
     *
     * @param key
     * @return
     */
    public static String readproperty(String key) {
        if(null == prop){
            Util.getPara();
        }
        try {
            prop.load(Util.class.getClassLoader().getResourceAsStream(FILENAME));
            return prop.getProperty(key);
        } catch (FileNotFoundException e) {
        } catch (IOException e) {
        }
        return null;

    }
    
    
}

 

posted @ 2015-11-11 09:12  临窗旋墨  阅读(190)  评论(0编辑  收藏  举报