3

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.

cfrick
  • 35,203
  • 6
  • 56
  • 68
VVB
  • 7,363
  • 7
  • 49
  • 83

2 Answers2

5

The temp directory is available via

String tempDir = System.getProperty('java.io.tmpdir')
Burt Beckwith
  • 75,342
  • 5
  • 143
  • 156
3

To create temp files in the default location for the OS you can use File.createTempFile(prefix,suffix)

cfrick
  • 35,203
  • 6
  • 56
  • 68
  • 1
    Also available via java.nio.file.Files.createTempFile. See https://docs.oracle.com/javase/8/docs/api/java/nio/file/Files.html#createTempFile-java.lang.String-java.lang.String-java.nio.file.attribute.FileAttribute...- – MikeOnline Mar 24 '21 at 22:55