so i have a war deployed, and i need to make a temp file. but when i make one in the java app it creates it in the tomcat root which is not equal to the web root... how do i create a tmp file in the root if i dont know where the application is executing from in relation to the tomcat root?


if you're using tempfiles you shouldn't care where they are as they're temporary anyway.

but if they arent accessable then the user cant dload them

Use the ServletContext's getRealPath() method to grab hold of the OS dependent real path of your web application's root. For e.g. on Windows system, it might look something along the lines of F:\Tomcat6\webapps\MyWebApplication] .

BTW, I am pretty sure that there are better ways of doing the thing you are trying there; just stream the generated bytes to the user by setting the appropriate response headers so that he gets the 'Save As / Open' pop up. Creating files and spawing threads and one of the few things you have to be *very* careful about in a managed environment.