1

I'm writing a Java program that has to create a folder on the disk, store some file in it, and when the program is terminated, the folder is deleted:

The problem is that, when my program is opened on a random pc, how should it know where to store files?

I saw a lot of installers that already suggest you a path (like "Program Files", "Roaming" etc), how can I make my program know these paths? Thanks.

Dea5
  • 131
  • 1
  • 9

1 Answers1

3

The standard path is

System.getProperty("java.io.tmpdir");

See: https://docs.oracle.com/javase/7/docs/api/java/lang/System.html#getProperties()

you might use it together with

File.createTempFile();

as suggested in this answer: https://stackoverflow.com/a/617438/7023245

Community
  • 1
  • 1
Timothy Truckle
  • 15,071
  • 2
  • 27
  • 51