tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jerry Ford <>
Subject writing a file from a servlet
Date Sun, 01 Feb 2004 23:12:10 GMT
I want to write a config file from a servlet implemented in 
to a myWebapp/conf directory.  The directory exists, and there are no 
permissions issues---I can write the config file if I hardcode a full 
path to the file.

The following works:

FileWriter fwrite;

   fwrite = new File 
Writer("/usr/local/webserver/tomcat/webapps/myWebapp/conf/" + project + 
   // ...etc.
catch(IOException e)
   // ...etc.

But if I change the path in the new FileWriter statement to any of the 
following, it does not work:

   /myWebapps/conf (relative to tomcat's servlets root)
   conf/ (relative to the docBase declared in the webapp's context)
   ../../../../conf (relative to the class file)

I get a FileNotFound...(No such file or directory) exception.

What does tomcat consider to be the relative path to the myWebapp/conf 
directory?  relative to what?

BTW, this is a private, internal app that won't be deployed in a public 
website, so there are no concerns about writing files to the server's 
disk.  But I want to reserve the option of deploying to a Windows 
machine or keeping it on the Linux box, and I don't want to be tied to a 
specific directory location on either box. 



To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message