Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When does System.getProperty("java.io.tmpdir") return "c:\temp"

People also ask

What is ${ Java IO Tmpdir in Windows?

getProperty("java. io. tmpdir") to get the default temporary file location. For Windows, the default temporary folder is %USER%\AppData\Local\Temp. For Linux, the default temporary folder is /tmp.

Where does Java store temp files?

getProperty("java. io. tmpdir"); Commonly, in Windows, the default temporary folder is C:\Temp , %Windows%\Temp , or a temporary directory per user in Local Settings\Temp (this location is usually controlled via the TEMP environment variable).

How is Java IO Tmpdir set?

The default temporary-file directory is specified by the system property java. io. tmpdir. On UNIX systems the default value of this property is typically "/tmp" or "/var/tmp"; on Microsoft Windows systems it is typically "c:\temp".

What is the use of Java IO Tmpdir?

The java. io. tmpdir system property indicates the temporary directory used by the Java Virtual Machine (JVM) to create and store temporary files. The default value is typically "/tmp" , or "/var/tmp" on Unix-like platforms.


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:

  1. The path specified by the TMP environment variable.
  2. The path specified by the TEMP environment variable.
  3. The path specified by the USERPROFILE environment variable.
  4. The Windows directory.

On the other hand, please check the historical reasons on why TMP and TEMP coexist. It's really worth reading.