Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to store temporary files in a Java web application?

I'm developing a java/spring-mvc web app that using a scheduling system generate csv files to send via e mail.

My first idea was to generate these files locally in server and then send them to recipients, but now I have a doubt. Where to store temp files?

I will deploy my application as a war, so I know there could be problems.

Is it a bad idea to create a temporary directory in my WEB-INF directory? An alternative could be to serialize these files and store them in a database table.

What's your suggestion? any best practice?

like image 835
davioooh Avatar asked Jul 31 '13 14:07

davioooh


1 Answers

I would left it on jvm, i.e. use java.io.tmpdir system property. Create a directory in tmp dir (new File(system.getProperty("java.io.tmpdir")).mkdir()) or just a file in the tmp directory (File.createTempFile("name", ".csv")).
For application running on Tomcat, the tmp dir is <catalina_home_directory>/temp.

like image 110
agad Avatar answered Sep 17 '22 12:09

agad