读取配置文件中的值

/**
* 加载配置文件
* @author
*
*/
public class ConfigUtil {
//实例属性(对象属性)
private static Properties ps = new Properties();

static{
/*
* 在加载类的同时,告诉类加载器,将此文件加载到内存
*/
InputStream in = ConfigUtil.class.getClassLoader().getResourceAsStream("db.properties");
try {
ps.load(in);
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 根据key获取文件当中的value
*
*/
public static String getValue(String key){
return ps.getProperty(key);
}

public static void main(String[] args) {

}
}

posted on 2016-09-18 18:51  arocky  阅读(549)  评论(0编辑  收藏  举报

导航