首页 > 其他 > 详细

读取配置文件中的值

时间:2016-09-18 19:17:51      阅读:163      评论:0      收藏:0      [点我收藏+]

/**
* 加载配置文件
* @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) {

}
}

读取配置文件中的值

原文:http://www.cnblogs.com/hy168/p/5882685.html

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