我正在使用Java编写一个程序,从XML文件中读取并解析数据。该文件被导入到我的项目的src目录下的名为“Resources”的文件夹中。我正在使用Eclipse。当我运行程序时,我遇到了以下错误:
java.io.FileNotFoundException: /Users/thechiman/Dropbox/introcs/PSU SOC Crawler/resources/majors_xml_db.xml (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
...
相关代码如下:
private void parseXML() {
//Get a factory
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {
//Use factory to get a new DocumentBuilder
DocumentBuilder db = dbf.newDocumentBuilder();
//Parse the XML file, get DOM representation
dom = db.parse("resources/majors_xml_db.xml");
} catch(ParserConfigurationException pce) {
pce.printStackTrace();
} catch(SAXException se) {
se.printStackTrace();
} catch(IOException ioe) {
ioe.printStackTrace();
}
}
我不明白为什么文件明明存在,却收到了FileNotFoundException异常。谢谢你的帮助。