aspose file tools*
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Writing Files in Tomcat?" Watch "Writing Files in Tomcat?" New topic
Author

Writing Files in Tomcat?

Paulo Aquino
Ranch Hand

Joined: Apr 29, 2002
Posts: 200
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.

Tomcat_Dir
---webapps
------my_application
---------WEB-INF
------------classes
------------lib
------------src
------------xml

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
Rancher

Joined: Mar 22, 2000
Posts: 12803
    
    5
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.
Bill
Paulo Aquino
Ranch Hand

Joined: Apr 29, 2002
Posts: 200
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
Marshal

Joined: Jan 10, 2002
Posts: 61415
    
  67

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


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