try{
String url = this.getClass().getResource("").getPath().replaceAll("%20", " ");
String path = url.substring(0, url.indexOf("WEB-INF")) + "WEB-INF/config.properties";
Properties config = new Properties();
config.load(new FileInputStream(path));
System.out.println(config.getProperty("dbDriver"));
} catch (Exception e){
e.printStackTrace();
}
转自:[url]http://www.blogjava.net/xiaosilent/archive/2006/12/22/89575.html[/url]
Java加载配置文件示例
本文展示了一个使用Java从特定路径加载配置文件并打印出指定属性值的例子。通过获取当前类的资源路径,并从中截取出配置文件的位置,利用Properties类加载文件并读取属性。
1265

被折叠的 条评论
为什么被折叠?



