I am writing a program in Java where I read data from an XML file and parse it. The file is imported into a folder named "Resources" in the src directory of my project. I am using Eclipse. When I run the program, I get the following error:
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)
...
The relevant code is here:
private void parseXML() {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder db = dbf.newDocumentBuilder();
dom = db.parse("resources/majors_xml_db.xml");
} catch(ParserConfigurationException pce) {
pce.printStackTrace();
} catch(SAXException se) {
se.printStackTrace();
} catch(IOException ioe) {
ioe.printStackTrace();
}
}
I do not understand why I get a FileNotFoundException when there is a file. Thanks for the help.
source
share