I want to improve the cross platform behavior of a java application. However, its test suite currently assumes the existence of the /tmp directory.
What is the best equivalent location on the windows platform? N.B. I most definitely do not want to assume the user has admin rights but I do want it to work on at least XP, Vista & Windows7.
Is there an existing environment variable that would help, and/or a set of preferred locations I could try in order of preference?
The system property
java.io.tmpdircan be used for the user’s temp directory:This may be preferred over
File.createTempFile(which, in any case, uses thetmpdirsystem property under the hood) in the instance where you want to search for temp files (for example, cached data from a previous invocation of your application, which sounds like it might be the case from your question).You can change the value of the system property by providing a runtime override on the command line (a
JVMargument):-Djava.io.tmpdir=C:\foo\barNote: the “trailing slash” issue descibed in the comments to seth‘s answer below can be avoided by using the relevant
Fileconstructor:Obviously windows also has an
DOSenvironment variable%TEMP%which could be used from any scripts which you have