FileNotFoundException when reading .xml file to parse

Posted by thechiman on Stack Overflow See other posts from Stack Overflow or by thechiman
Published on 2010-04-04T22:09:38Z Indexed on 2010/04/04 22:13 UTC
Read the original article Hit count: 438

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.

© Stack Overflow or respective owner

Related posts about java

Related posts about filenotfoundexception