Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Beginners Find Current Temp Directory

 
 

Share on Google+Share on Google+

Find Current Temp Directory

Advertisement
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 "java.io.tmpdir" 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("java.io.tmpdir"));
  }
}

The output of the program is given below:

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

Download this example.

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  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.

Posted on: June 29, 2007

Related Tutorials

Discuss: Find Current Temp Directory  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:4
DWIGHT BALL MORRILL
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("java.io.tmpdir") 2040 LET DIR$=STR(inDir!) I need the directory returned in the variable DIR$.
Teige
September 22, 2011
mutSidAVcfUJSZEBffi

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

Gives Result as null,
Host
May 22, 2012
Incorrect Example

There is no such key as java.io.tmpdir,, instead try with TEMP
DMCA.com