FileNotFoundException when reading .xml file to parse
- by thechiman
I'm writing a program in Java where I read in 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'm 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() {
//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();
}
}
I do not understand why I'm getting the FileNotFoundException when the file is there. Thanks for the help.