java.io.tempdir
Java System Property allows you to read or set a temporary directory for use by the java runtime.The default value will differ based upon the operating system that java is running on.
java.io.tempdir
ExplainedThe 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
Here are some other File Path related Java system properties:
Java has supported the java.io.tempdir
system property since at least Java 1.4, support may go back even further.
java.io.tempdir
on StartupYou 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
java.io.tempdir
at RuntimeYou 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"); }