Results 1 to 4 of 4
- 06-10-2011, 07:37 AM #1
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:
Here's the error I'm getting: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; }
Now: the xml file and the dtd are under the project name, and they're spelled correctly. Please can someone help me?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)
- 06-10-2011, 08:04 AM #2
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.Java Code:System.out.println(System.getProperty("user.dir"));
- 06-10-2011, 10:00 AM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
The other way (which has the same effect) is:
Java Code:File f = new File("Colors.xml"); System.out.println(f.getAbsolutePath());
- 06-10-2011, 04:21 PM #4
Similar Threads
-
FileInputStream not recognising file
By javabarn in forum New To JavaReplies: 3Last Post: 07-08-2010, 09:52 PM -
NullPointerException in FileInputStream text file
By cheskers11 in forum EclipseReplies: 1Last Post: 11-19-2009, 01:38 PM -
Alternative of FileInputStream to read Property File
By SE123 in forum Java ServletReplies: 13Last Post: 09-16-2009, 01:05 PM -
java.io.FileNotFoundException: (No such file or directory)
By sudukrish in forum Advanced JavaReplies: 1Last Post: 04-01-2009, 07:34 PM -
[SOLVED] Trouble with Scanner FileInputStream not finding the file
By miss.meli in forum New To JavaReplies: 0Last Post: 12-01-2008, 09:50 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks