To get the location of temporary directory we can use the System.getProperty(String)
method and pass a property key "java.io.tmpdir"
as the argument to the method.
package org.kodejava.lang;
public class TempDirExample {
public static void main(String[] args) {
// This is the property name for accessing OS temporary directory
// or folder.
String property = "java.io.tmpdir";
// Get the temporary directory and print it.
String tempDir = System.getProperty(property);
System.out.println("OS temporary directory is " + tempDir);
}
}
The output of code snippet above is:
OS temporary directory is C:\Users\wsaryada\AppData\Local\Temp\
Latest posts by Wayan (see all)
- How do I get number of each day for a certain month in Java? - September 8, 2024
- How do I get operating system process information using ProcessHandle? - July 22, 2024
- How do I sum a BigDecimal property of a list of objects using Java Stream API? - July 22, 2024
Thanks