Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

FileNotFoundException when file exists.

 
Brian Egger
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been trying to figure this out for a while but it's not working no matter what I try. I have an application that takes input from a user, then turn the input into an XML file using Betwixt. Once the file is generated I read it from Digester and process data. The problem I have is on my local environment I have not problem generating the file then reading it, on my test (Linux) server I can not read the file after I generate it, only on the linux box. If I hand code a file and upload it to the file repository where generate to I can read it fine, it's only when I use my application to generate it. Also after I generate the file is there, I can download it with WinSCP, but If I try to overwrite the file I get an error in WinSCP, I can only delete and replace. Something might still have a hold of the file in memory, maybe..?? The Exception is as followed as well as the code I use to generate the file thanks.


java.io.FileNotFoundException: /pages/content/net/tool/OpFinderCategoryReview.xml (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at org.apache.commons.digester.Digester.parse(Digester.java:1554)
at com.spectra.logic.core.Evaluate.digest(Evaluate.java:24)
at com.spectra.logic.core.MasterControlProgram.parseDocument(MasterControlProgram.java:41)
at com.spectra.logic.core.MasterControlProgram.doExecute(MasterControlProgram.java:30)
at com.spectra.web.display.page.CalculateLookupDispatchAction.calculate(CalculateLookupDispatchAction.java:74)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:868)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:663)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)





Thanks in advance.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
FileNotFoundException is really misnamed - a lot of times it is thrown if proper access permissions are missing. Check which permissions are set on the file, and under which account the server (or application) is running.
 
Brian Egger
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did do a chmod 664 on the file, the same as the other files, but it did nothing. Should I chown. I also wrote some code for File.exists() and it came back false, so I am drawing a complete blank.

Thanks,
Brian
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Go through the hierarchy of directories that leads to this file, and check that the code can access every single one. Or is it just this one file that's giving you trouble, and others in the same directory work fine?
 
Brian Egger
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I create an XML file through an editor and upload it works fine. It works if I generate the file on Windows, but not on Linux. Also, I chowned the file to my user name and did a chmod 777 on the file it's self, but I got nothing. I pasted the file path the exception gave me into a shell and VI'ed it and it was fine. So I think something in the app might have a hold of it still. I did a BeanWriter.flush() BeanWriter.close() and a FileOutPutStream.flush() and a FileOutPutStream.close(). So I don't know what else it could be, I am at a loss.

Thanks,
Brian
 
Brian Egger
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, so now it's getting time that I really figure this one out. The application has to migrate to the Linux server. So here is the deal. The is not a permission issue for Unix, and this is how I know. I can access the file from a JSP if I use scriptlet code, and I also wrote another small project to access files in the same directory I created with my other application and that works fine as well. It will not access any file that my application generated by way of a Java class, I tired putting the file access logic in the ActionServlets I tried with a different class, it won't access files that it generated, but files I write from hand and upload, they are accessed fine. I am at wit's end here. I have no explaination as to how this could be.

Any help would be greatly appreciated.
Brian
 
Jan Cumps
Bartender
Posts: 2588
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible that /pages is relative to your web application?

The jsp page will be able to find your file, because it's root is the root of your web application.

When you try to open the file from a Java class, it will try to locate /pages in the root of your operating system.

Regards, Jan
 
Purushoth Thambu
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to understand what you have tried on permission check. It's quite possible that the application runs under different user/permission. How is your application started and with what permission?. If it has been started with root permission probably that's the cause. I assume file is generated by different process and read by different process.
 
Brian Egger
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to access the file from the root of the operating system, and that's the weird thing, if I use my application to generate the file it cannot be accessed. If I write the file from scratch and WinSCP it up to the server it can access it all day long. This problem is super crazy.

Brian
 
Brian Egger
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well the application is running on a test server, on Tomcat 5.5.12. There are few applications running on the same server. I deploy it through the tomcat manager, the way I start it is through sudo with my username. I can try su in to the root and start that way, but I don't think it will have much difference, seeing as my other applications on the same server can access the file.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic