Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practice to save temp files on tomcat? [duplicate]

I need to demo a xml based data interchange system. It is demoed offline on a trusted computer at school. The application will get database later but just for this presentation I only need to show the layout, opening and saving of xml-files and how the table gets data from the xml.

So, what would be the best location to let the web app create the xml files temporarily so I can showcase this app? I'm using Eclipse and Tomcat.

As mentioned, security is not an issue at all, since this version is NOT going to be online. Also, it's ok if the files get erased each time the application is run.

They need to exist only for the duration of the presentation where the application is run once. So, I'm clueless what would be the best location and how to get the path to such location not depending on the computer used.

Thank you.

like image 750
Steve Waters Avatar asked May 21 '14 06:05

Steve Waters


People also ask

Can I delete Tomcat temp files?

Yes, the tomcat/temp directory is safe to delete when the server is stopped.

Where are temp files stored Java?

The file directory is the directory where the temporary file will be stored.

How do I create a temp file?

To create and use a temporary fileThe application opens the user-provided source text file by using CreateFile. The application retrieves a temporary file path and file name by using the GetTempPath and GetTempFileName functions, and then uses CreateFile to create the temporary file.


2 Answers

Use the property java.io.tmpdir to get the tomcat temp folder and save your files there. That will be a good place to temporarily keep them in. So you can define it as follows:

public static final String TMP_DIR = System.getProperty("java.io.tmpdir")
like image 56
Omoro Avatar answered Sep 18 '22 10:09

Omoro


Either use the property java.io.tmpdir as indicated or use the servlet context attribute javax.servlet.context.tempdir defined in the specification. For tomcat that attribute can be changed by the workDir attribute on the context.

You can use that attribute by a call to servletContext.getAttribute("javax.servlet.context.tempdir")

See tomcat documentation for detail.

like image 37
Cédric Couralet Avatar answered Sep 21 '22 10:09

Cédric Couralet