jQuery in Action, 3rd edition
The moose likes Tomcat and the fly likes Writing Files in Tomcat? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Writing Files in Tomcat?" Watch "Writing Files in Tomcat?" New topic

Writing Files in Tomcat?

Paulo Aquino
Ranch Hand

Joined: Apr 29, 2002
Posts: 202
How can i specify where tomcat writes my file? You see I have a code that writes String in to a file.

Lets say my filename is TestWrite so, the comp filename is TestWrite.xml. This file gets written on the root tomcat directory (c:\tomcat_dir). I want to write this file relative to its directory in the webapps directory.


I want to write it to the xml folder.How can I do that?

Be Afraid...Be very Afraid...
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13036
You will have to specify a complete path - otherwise the file gets written wherever Tomcat happens to think the "current" directory is.
Look at the ServletContext getRealPath method.
Paulo Aquino
Ranch Hand

Joined: Apr 29, 2002
Posts: 202
What if the code listed below is in a java helper class and not in a servlet? I can't use servlet context right? My jsp page is calling a java helper class to write the xml file. Anymore suggestions?
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63844

The file path will need to be passed to the helper class.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link: http://aspose.com/file-tools
subject: Writing Files in Tomcat?
It's not a secret anymore!