该资源需要添加为URL,否则String将被解释为类路径资源(目前无法解析并被忽略-我知道你认为警告消息会被转储到某个地方):
/**
* Add a configuration resource.
*
* The properties of this resource will override properties of previously
* added resources, unless they were marked <a href="#Final">final</a>.
*
* @param name resource to be added, the classpath is examined for a file
* with that name.
*/
public void addResource(String name) {
addResourceObject(name);
}
无论如何,试试这个(我在系统错误中得到黄色):
@Test
public void testConf() throws MalformedURLException {
Configuration conf = new Configuration();
conf.addResource(new File("~/conf.xml")
.getAbsoluteFile().toURI().toURL());
conf.reloadConfiguration();
System.err.println(conf);
System.err.println(conf.get("color"));
}