java.io.tempdir Java System Property
The
java.io.tempdir
Java System Property allows you to read or set a temporary directory for use by the java runtime.
Default Value
c:\temp\
/tmp/
The default value will differ based upon the operating system that java is running on.
java.io.tempdir
Explained
The java.io.tempdir system property defines the file system path of a temporary directory for use by the java runtime.
As of Java 20, a warning message will be displayed if the temporary directory does not exist upon startup of the JVM:
WARNING: java.io.tmpdir directory does not exist
Related System Properties
Here are some other File Path related Java system properties:
file.encoding
file.separator
jdk.io.File.enableADS
Supported Since
Java has supported the
java.io.tempdir
system property since at least Java 1.4, support may go back even further.
Setting
java.io.tempdir
on Startup
You can set the
java.io.tempdir
java system property during startup of the java runtime using the
-D
command line argument:
java -Djava.io.tempdir=c:\temp MyAppMain
You may also be able to specify
java.io.tempdir
via the
JAVA_TOOL_OPTIONS
environment variable:
JAVA_TOOL_OPTIONS=-Djava.io.tempdir=c:\temp
Setting / Reading
java.io.tempdir
at Runtime
You can set java.io.tempdir at runtime with the following Java code:
System.setProperty("java.io.tempdir", "c:\temp");
WARNING: Depending on the property and JVM version using
setProperty
may or may not work if the JDK Java class that uses this variable has already been loaded. The value of the java.io.tempdir system property may be cached within an internal private static variable of the implementing class.
To read the value of java.io.tempdir at runtime, you can use this Java code:
String propertyValue = System.getProperty("java.io.tempdir");
if (propertyValue != null) {
System.out.println("java.io.tempdir = " + propertyValue);
} else {
System.out.println("java.io.tempdir was null");