How to access Java tmp directory

Java defines an environment variable with the user temp directory that can be accessed programatically.


String tmpDirectory = System.getProperty("");

Here is an example that accesses the variable from from the System object. The variable is saved in a String and displayed in the output.

Create the following java file:

public class TmpDirectory {

	public static void main(String[] argv){
		String tmpDirectory = System.getProperty("");

		System.out.println( "The tmp directory is " + tmpDirectory ); 

The output will be:

The tmp directory is C:\Users\Olivier\AppData\Local\Temp\

The variable can be passed to the JVM using the parameter, example In a J2EE environment the temporary directory points to the application server tmp directory.


Setting up the Java IO Temp Location

Recent Comments