Share on Google+Share on Google+

Find Current Temp Directory

This section provides you an example that searches the current Temp directory.

Find Current Temp Directory 


In this example we are find the current Temp directory.

We are using getProperty(String key) method to find the current temp directory. The getProperty(String key) is defined into System class. System class extends directly Object class. System class is defined final so any class never extends System class. System class allow us to get or set system information. In this example we are pasing "" as key to get the current temp directory into getProperty() method.

The code of the program is given below:

public class TempDirExample 
  public static void main(String[] args)
  System.out.println("OS current temporary directory is "
+ System.getProperty(""));

The output of the program is given below:

C:\convert\rajesh\completed>java TempDirExample
OS current temporary directory is C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\

Download this example.


Posted on: June 29, 2007 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: Find Current Temp Directory  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
June 16, 2011
client workstation default temp directory

I need the code to get the "client" workstation default temp directory not the server temp directory. Now I'm using this and it gives me the server temp directory. 2035 inDir! =java.lang.System.getProperty("") 2040 LET DIR$=STR(inDir!) I need the directory returned in the variable DIR$.
September 22, 2011

Well I guess I don't have to spend the weekend fgiuirng this one out!
May 22, 2012
Incorrect Example

Gives Result as null,
May 22, 2012
Incorrect Example

There is no such key as,, instead try with TEMP