Java defines an environment variable with the user temp directory that can be accessed programatically.
String tmpDirectory = System.getProperty("java.io.tmpdir");
Here is an example that accesses the java.io.tmpdir variable from from the System object. The variable is saved in a String and displayed in the output.
public class TmpDirectory { public static void main(String[] argv){ String tmpDirectory = System.getProperty("java.io.tmpdir"); System.out.println( "The tmp directory is " + tmpDirectory ); } }
The tmp directory is C:\Users\Olivier\AppData\Local\Temp\
The variable can be passed to the JVM using the parameter java.io.tmpdir, example -Djava.io.tmpdir=/tmp. In a J2EE environment the temporary directory points to the application server tmp directory.
Setting up the Java IO Temp Location