Skip to main content

Where to generate and store temporary files?

1 reply [Last post]
Joined: 2007-05-25
Points: 0

My managed bean will generate PDF based on the user inputs. These PDFs are temporary, it is only valid for one specific request. I'm wondering where is the correct directory I should generate these PDFs ...
Currently, I'm generating these PDFs to C:\glassfish3\glassfish\domains\domain1\applications\myapp like this:

ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();

// path is C:\glassfish3\glassfish\domains\domain1\applications\myapp

String path = context.getRealPath("/");

File temp = new File(path, "summary.pdf");

Is there a better place to store temporary files?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2005-04-23
Points: 0

In java, The location of the directory used to hold temporary files is defined by the property

File tempDir = new File(System.getProperty(""));

It is better to store your PDF files there instead of the root directory ( context.getRealPath("/") ) of your JSF application.