webtier@glassfish.java.net

Re: Where to generate and store temporary files?

From: Ryan Lubke <ryan.lubke_at_oracle.com>
Date: Fri, 20 May 2011 10:46:31 -0700

On 5/20/11 10:18 AM, forums_at_java.net wrote:
> Hi
>
> 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?

You can use the /javax/./servlet/./context/./tempdir/ attribute
(provided by the Servlet container, free of charge). The value of this
attribute is of type File and is guaranteed to be a directory. When the
application is undeployed, this should be cleaned up.

>
>
> --
>
> [Message sent by forum member 'hezjing']
>
> View Post: http://forums.java.net/node/804682
>
>