qileilove

blog已经转移至github,大家请访问 http://qaseven.github.io/

Java Application下读取properties配置文

 在java应用程序开发中,经常需要读取配置文件来获取系统参数或配置信息。配置文件可以使用xml格式文件,在java中存在.properties文件专门用作配置文件使用。在java中,类Properties用于处理配置文件相关的读取。下面是一个关于根据所提供的键获取值的示例。
public static String getvalue(String key)
{
Properties p=new Properties();
FileInputStream fis;
String url = new File("").getAbsolutePath() + File.separator+  "config.properties"; // 获取位于工程根目录下的config.properties配置文件绝对路径
try {
fis = new FileInputStream(url);
p.load(fis);
fis.close();
} catch (Exception e) {
// TODO Auto-generated catch block
System.out.print("problems with properties");
e.printStackTrace();
}
return p.getProperty(key);
}

posted on 2013-12-02 09:10 顺其自然EVO 阅读(309) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 
<2013年12月>
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

导航

统计

常用链接

留言簿(55)

随笔分类

随笔档案

文章分类

文章档案

搜索

最新评论

阅读排行榜

评论排行榜