我正在尝试在java.But中读取xml文件我面临FilenotFoundException。可以帮助任何人吗?
源代码:
Properties props = new Properties();
FileInputStream fis;
try {
fis = new FileInputStream("src/org/inbound/service/db/dbdetails_remedey.xml");
try {
props.loadFromXML(fis);
} catch (IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
例外:
java.io.FileNotFoundException: src\org\inbound\service\db\dbdetails_remedy.xml (The system cannot find the path specified)
答案 0 :(得分:1)
您应该从类路径加载文件。使用对象方法getClass()
;
示例:getClass().getClassLoader().getResource("foo.xml")
;