On Thu, 2015-01-29 at 00:33 +0530, Hyder Hashmi wrote:
> Hi,
> 
> I am working on a small project and need your help in this.
> 
> I have a java program in which I read and write in a file that is
> located in the current folder.
> 
> Now I have written a few servlets and trying to use the previous code
> along with servlets.
> 
> Tomcat is searching for the file in its bin folder and giving
> FileNotFoundException. 
> 
> If I use my java code without the servlet it is checking for the file
> in current folder (which is my requirment).
> 
> I want to ensure that when I use my java code along with servlets, it
> should read and write in the file from current folder(Project folder
> in tomcat's webapps).

It sounds like you're trying to force your notion of what a web app's
"current folder" should be onto Tomcat.  It simply doesn't work that
way.  The Servlet Spec makes no guarantee as to what the "current
folder" is (a file system notion) in a Servlet container or web app.

Suggest you modify your file processing class to accept a hint as to the
"current folder" and set that value in the servlet using
ServletContext.getRealPath("/") and/or via an init parameter or via
injection.  But note that if the web app is deployed as an unexploded
war file getRealPath() may return null.

--- Tim

> I am not using any IDE, the  code is written in Notepad and being
> executed from CommandLine.
> 
> I have spent long time on Internet to find the resolution but in vain.
> 
> Request to help me with this situation .
> 
> Hoping for a positive reply.
> 
> Thanks for in advance for all the help.
> 
> Regards,
> Hyder.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to