I am writing a Java application that writes a number of files, and later reads the files for their values. I am using InstallShield to install the application under C:\Program Files, and this is where the temporary files usually get created. However, when using Windows 7, the files are created under the users temporary folder instead, with a random name.
Here is my code…
File usersTemp = File.createTempFile("users", null,temp);
And this is the file that gets generated…
C:\Users\TP\AppData\Local\Temp\users2343200092608531612.tmp
As the file is generated with a random number, it makes it hard to retrieve the file back for processing. Is there a better way to do this?
Unless you’re running as a superuser (which you’re probably not), you can only edit files in the user’s home directory, which you can find with the
user.homesystem property:So, if you wanted to save a file in your application’s application data folder:
Then save things under that folder and they will stick around.