Results 1 to 4 of 4
  1. #1
    horndinkle's Avatar
    horndinkle is offline Member
    Join Date
    Nov 2010
    Posts
    11
    Rep Power
    0

    Default FileNotFoundException, FileInputStream, File

    I'm at my wit's end. <grumble> I'm getting a FileNotFoundException when I try to read in a file. Here's the relevant code:
    Java Code:
        public List<String> getList() throws IOException {
    
    	    List<String> colorsList = null;
    
            Element element = null;
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    
            try {
                colorsList = new ArrayList<String>();
                DocumentBuilder parser = factory.newDocumentBuilder();
                Document doc = parser.parse(new FileInputStream(new File(
                        "Colors.xml")));
                Element root = doc.getDocumentElement();
                NodeList nodes = root.getChildNodes();
    
                for (int i = 0; i < nodes.getLength(); i++) {
                    Node node = nodes.item(i);
                    if (!(node instanceof Element)) {
                        continue;
                    }
                    element = (Element) node;
                    colorsList.add(element.getAttribute("name"));
                    logger.info("color=" + element.getAttribute("name"));
                }
            } catch (IOException e) {
                e.printStackTrace(System.out);
            } catch (ParserConfigurationException e) {
                e.printStackTrace();
            } catch (SAXException e) {
                e.printStackTrace();
            }
    
            return colorsList;
    	}
    Here's the error I'm getting:
    Java Code:
    java.io.FileNotFoundException: Colors.xml (The system cannot find the file specified)
    	at java.io.FileInputStream.open(Native Method)
    	at java.io.FileInputStream.<init>(Unknown Source)
    	at model.serviceLayer.Colors.ColorsSvcXmlImpl.getList(ColorsSvcXmlImpl.java:52)
    	at model.businessLayer.Colors.ColorsMgr.getList(ColorsMgr.java:35)
    	at taglib.ListTag.doStartTag(ListTag.java:27)
    	at org.apache.jsp.view.ColorList_jsp._jspx_meth_myTags_005fcolorList_005f0(ColorList_jsp.java:179)
    	at org.apache.jsp.view.ColorList_jsp._jspService(ColorList_jsp.java:112)
    	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
    	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
    	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
    	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
    	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
    	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
    	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)
    	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    	at java.lang.Thread.run(Unknown Source)
    Now: the xml file and the dtd are under the project name, and they're spelled correctly. Please can someone help me?

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default

    Java Code:
    System.out.println(System.getProperty("user.dir"));
    Add that line to the start of your code. This will display your current working directory and where your code is trying to find your file.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,820
    Rep Power
    19

    Default

    The other way (which has the same effect) is:
    Java Code:
    File f = new File("Colors.xml");
    System.out.println(f.getAbsolutePath());

  4. #4
    horndinkle's Avatar
    horndinkle is offline Member
    Join Date
    Nov 2010
    Posts
    11
    Rep Power
    0

    Default

    Well, I found out what directory I'm in. It makes a kind of sense, but it's still irritating. It was C:\apache\apache-tomcat-7.0.12. (#@#$#$!!) Thanks for all your help! It was wonderful!

Similar Threads

  1. FileInputStream not recognising file
    By javabarn in forum New To Java
    Replies: 3
    Last Post: 07-08-2010, 09:52 PM
  2. NullPointerException in FileInputStream text file
    By cheskers11 in forum Eclipse
    Replies: 1
    Last Post: 11-19-2009, 01:38 PM
  3. Replies: 13
    Last Post: 09-16-2009, 01:05 PM
  4. Replies: 1
    Last Post: 04-01-2009, 07:34 PM
  5. Replies: 0
    Last Post: 12-01-2008, 09:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •