0
每当我尝试按以下方法加载属性文件时。我得到原样使用Java加载属性文件
上
getClass()
错误无法从Object类型
public static void main(String[] args) {
---
---
loadProperties(line);
}
private static void loadProperties(String line) {
Properties prop = new Properties();
InputStream in = getClass().getResourceAsStream("foo.properties");
try {
prop.load(in);
for(Object str: prop.keySet()) {
Object value = prop.getProperty((String) str);
System.out.println(str+" - "+value);
}
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
任何建议,我怎么能解决这个使静态参考非静态方法的getClass()。
需要注意的是,如果你使用'的getClass()',而不是一类的文字,有趣的事情可以在子类的存在下发生(你可能会得到与你想象的不同的包)。 – Thilo