How to get operating system temporary directory in java

This example shows you how to get the system temporary directory full path using java.

There is one system property key named as ‘java.io.tmpdir’, we can use this property to get the value of temporary directory

Below is the example code of getting the temporary directory in window 7 operating system.

package com.java.connect.lang;
 
//How to get operating system temporary directory in java
public class TemporyDirectoryExample {
    public static void main(String[] args) {
        // There is one system property key named as 'java.io.tmpdir'
        // We can use this property to get the value of tmp directory.
        String property = "java.io.tmpdir";
 
        // Get the temporary directory and print it.
        String temp = System.getProperty(property);
        System.out.println("The Current temporary folder is " + temp);
    }
}

The output of above example will be as:

The Current temporary folder is D:\Users\SUDA\AppData\Local\Temp\