8

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?

davioooh
  • 22,098
  • 37
  • 145
  • 234

2 Answers2

8

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.

agad
  • 2,152
  • 1
  • 19
  • 31
1

How to create a temporary directory/folder in Java? - also on how to do this the best way in Java 7.

It really sounds like simple temporary files are exactly what you need - and you don't really need to worry about where to store them, Java does that for you. Why would you store them in a DB if you'd only need them temporarily? Databases are for persistent storage you care about. And the hassle of serializing, neh...

Community
  • 1
  • 1
qkrijger
  • 25,948
  • 6
  • 34
  • 37