Simple answer: don't do that. Write your logs somewhere else, outside the web application.
Joined: Jan 22, 2004
Thanks for the replies. No, I don't have to use getRealPath() and I'm happy to write the files outside the web application. How then, could my servlet create a subdirectory in the root directory then output the files there (without hardcoding in any absolute paths)?
James Hodgkiss wrote:Thanks for that, but my web app is deployed in an unexploded way.
Bearing that in mind, is there any way my servlet can create a subdirectory in the root directory then output the files there (without hardcoding any absolute paths into my web app)?
It's unlikely. The user id that is running the web container is not likely a root user (it shouldn't be) so it won't be able to create directories off the root. Consider using an existing directory such as /var/log/.
I'm still not sure why you need to create a directory for logging. Have you created your own logging framework? I've used log4j and java.util.Logging and both put the log files in /var/log/tomcat5.
You cannot create files or folders inside the war. And generally, even oif you could, you shouldn't create files or folders inside the web app. What happens to them when it comes time to redeploy or update the app?