我在程序中使用Properties的方法获取classpath下的log4j.properties文件信息
prop.load(**.class.getResourceAsStream(name), "utf-8");
但是有多个log4j.properties,怎么找出来所有的绝对路径?
我在程序中使用Properties的方法获取classpath下的log4j.properties文件信息
prop.load(**.class.getResourceAsStream(name), "utf-8");
但是有多个log4j.properties,怎么找出来所有的绝对路径?
使用 classloader 的 getResources 方法,可以获取相应资源的URL,有了URL就可以转换成绝对路径了。
[code="java"]for(URL url: this.getClass().getClassLoader().getResources("log4j.properties")){
String path = url.getPath();
//你的代码 ...
}[/code]