首页 > 其他 > 详细

工具类

时间:2015-11-11 09:58:36      阅读:267      评论:0      收藏:0      [点我收藏+]
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;

    }
    
    
}

 

工具类

原文:http://www.cnblogs.com/widow/p/4955179.html

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