• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Writing Files in Tomcat?

 
Paulo Aquino
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The file path will need to be passed to the helper class.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic