When does System.getProperty("java.io.tmpdir") return "c:\temp"
In MS Windows the temporary directory is set by the environment variable TEMP
. In XP, the temporary directory was set per-user as Local Settings\Temp.
If you change your TEMP environment variable to C:\temp
, then you get the same when you run :
System.out.println(System.getProperty("java.io.tmpdir"));
If you set
-Djava.io.tmpdir=C:\temp
On the one hand, when you call System.getProperty("java.io.tmpdir")
instruction, Java calls the Win32 API's function GetTempPath
.
According to the MSDN :
The GetTempPath function checks for the existence of environment variables in the following order and uses the first path found:
- The path specified by the TMP environment variable.
- The path specified by the TEMP environment variable.
- The path specified by the USERPROFILE environment variable.
- The Windows directory.
On the other hand, please check the historical reasons on why TMP
and TEMP
coexist. It's really worth reading.