Search code examples
grailstemp

How to save files in temp directory for any platform?


I have a Grails application in which I generate PDF/Excel files in a folder.

My problem is, everytime I need to change the directory path through code when I test or run the code on different machines like Windows, Linux, Mac.

So what is the generic path, which will be applicable for any/all platforms as the default temp directory, so that I won't need to manually set path for the directory while running code on different machines/platforms.


Solution

  • The temp directory is available via

    String tempDir = System.getProperty('java.io.tmpdir')