Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using FileWriter in Tomcat 1

Status
Not open for further replies.

tdion

MIS
Dec 18, 2003
61
US
One of my JSPs writes a file. My declaration is...

FileWriter fw = new FileWriter("report.xls");

The file get created in the bin folder of Tomcat and not the folder where my JSPs are. Does anyone know how to control where new files are created?
 
Code:
File webroot = new File(session.getServletContext().getRealPath("/"));

this give you the file directory for your web root. You can start from there to go where you want.

e.g. to place the output file in <webroot>/report/report.xls, you can do:

Code:
FileWriter fw = new FileWriter(new File(webroot, "report/report.xls"));
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top