From FileNotFoundException API(SE6):
This exception will be thrown by the FileInputStream, FileOutputStream, and RandomAccessFile constructors when a file with the specified pathname does not exist. It will also be thrown by these constructors if the file does exist but for some reason is inaccessible, for example when an attempt is made to open a read-only file for writing.
Oct 15, 2010 12:48:55 PM org.apache.coyote.http11.Http11BaseProtocol init
INFO: Initializing Coyote HTTP/1.1 on http-80
Starting service Tomcat-Standalone
Oct 15, 2010 12:48:57 PM org.apache.coyote.http11.Http11BaseProtocol start
INFO: Starting Coyote HTTP/1.1 on http-80
Oct 15, 2010 12:48:57 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Oct 15, 2010 12:48:57 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/32 config=null
Can't open carbon.oak Error: java.io.FileNotFoundException: carbon.oak (The system cannot find the file specified)
The error message says that the tomcat can't find "carbon.oak". Does your app use this file?
I've searched at web and it looks like it is not related with tomcat.
and the Servlet can't find open the file.
Is there anywhere else the Servlet could be looking?
What is strange that it is opened fine in a similar Windows 2003 Server environment.
(1) Choose a directory and put the file there.
(2) Provide the full path to that directory to whatever is trying to open it.
However, I don't encourage putting user files in Tomcat's bin directory. Pick a place that isn't dedicated to a private purpose already.
Incidentally, if you want to read a file, don't plan on writing to the file and the file isn't expected to change, you can include it as a resource in your WAR and use the request getResourceAsStream to open an input stream on it.
One thing you should NEVER do is have a webapp write files into WARs, however!
Eric Racin wrote:I am using Server 2003. This is the the syntax:
BufferedReader is = new BufferedReader(new FileReader(sCarbonFile));
If I want to designate a directory, as you imply, would the syntax be:
BufferedReader is = new BufferedReader(new FileReader(/Tomcat/dir/sCarbonFile));
Better to say "C:/Tomcat/dir/sCarbonFile". Otherwise the path is ambiguous.
SOURCE : http://www.exampledepot.com/egs/javax.servlet/GetInit.html
Under servlet class add this
And read the parameter from the file as mentioned in the source.
This way you dont need to change your code file every time just change it in the XML where ever you take it.
Hope that helps!
I am going to provide you with a totally different solution than any which has been discussed here.
If I read correctly, you need to read a file into your web application and you are going to port the file along with the application wherever you host it. First and foremost do not use hard-coded absolute path, as has been suggested by some. This will tie your application down to the exact directory structure and becomes useless on any other kind of requirement.
To open a file you are going to need absolute path to the file so we go about getting the absolute path (sounds contradictory , read on) without having to change the code or disturbing the application.
There is a method in ServletContext interface called getRealPath this method coverts the virtual path of the application into an absolute path depending on the App Server + OS at runtime. So regardless of where you have deployed the application, this method will always give you the absolute path to the context of your web app, plus you don't even have to bother about confusion of slash (/) or backslash (\). This method returns a string, which is appropriate for your situation.
So get the real path to the context, attach the filename (with subdirectories if that applies) and then open this using the normal IO methods.
Hope that helps