How do I get operating system temporary directory / folder?

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.example.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);
    }
}

Wayan

Programmer, runner, recreational diver, live in the island of Bali, Indonesia. Mostly programming in Java, creating web based application with Spring Framework, Hibernate / JPA. Support me by donating >> here <<.

1 Comments

Leave a Reply