Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , , , ,

Sponsored Links


How to get operating system temporary directory using java program?

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 05-02-2010
Member
 
Join Date: Aug 2009
Posts: 57
How to get operating system temporary directory using java program?

Sponsored Links
Hi friends,
I am new to this forum. I am working on live project where I use java as front ens ans SQL as back end. In one of my page I have to show operating system temporary directory using. I tried various method but unable to write correct program. Can anyone help me how to get operating system temporary directory using java program? Please help me.
Thank you.

Reply With Quote
  #2  
Old 05-02-2010
Praetor's Avatar
Member
 
Join Date: Apr 2008
Posts: 1,943
Re: How to get operating system temporary directory using java program?

It is very simple to get operating system temporary directory in java. You have to just use java.io.tmpdir property name to get operating system temporary directory. Just save this property name into any string variable and then pass this variable to another string variable for retrieval.



Code:
package sample.code.java.lang;

public class TempDirEg
{
    public static void main(String[] args)
    {
       
        String properties = "java.io.tmpdir";
        
        
        String tempDirt = System.getProperty(properties);
        System.out.println("Windows xp current temporary directory is " + tempDirt);
    }
}
Reply With Quote
  #3  
Old 05-02-2010
Member
 
Join Date: May 2008
Posts: 2,000
Re: How to get operating system temporary directory using java program?

Using following program we are able to getoperating system temporary directory. In this following program I have use getProperty( ) method to get operating system temporary directory. The path specified by the TMP environment variable is used to get current directory. The getProperty() method is commonly used in such type of program. In the following program I have pass "java.io.tmpdir" to getProperty() method to get the current temp directory into getProperty() method. Just try to understand it.




Code:
public class TempDirEg
{
    public static void main(String[] argss)
    {
      
        System.out.printlns("OS current temporary directory is "
 + System.getPropertys("java.io.tmpdirs"));
    }
}
Reply With Quote
  #4  
Old 05-02-2010
kelfro's Avatar
Member
 
Join Date: Apr 2008
Posts: 1,989
Re: How to get operating system temporary directory using java program?

You have to just use following code in your program to get operating system temporary directory. It is very simple program. You have to just pass path name to another variable to get operating system temporary directory. In the following program I have use two variable named as "ss" and "cs". Just try to understand it.


Code:
Private Const MAX_LENGTHs = 3245

Public Function GetTempDirectory() As String
   Dim s As String
   Dim c As Long
   ss = Space$(MAX_LENGTHs)
   cs = GetTempPath(MAX_LENGTHs, ss)
   If cs > 0 Then
       If cs > Len(s) Then
           ss = Space$(cs + 1)
           cs = GetTempPath(MAX_LENGTHs, ss)
       End If
   End If
   GetTempDirectorys = IIf(cs > 0, Left$(ss, cs), "")
End Function
Reply With Quote
  #5  
Old 05-02-2010
Zecho's Avatar
Member
 
Join Date: May 2008
Posts: 2,278
Re: How to get operating system temporary directory using java program?

In the following program I have use java.io.File class to get operating system temporary directory. It is very simple program. In the following program I have use CurrentWorkingDirectory class to get operating system temporary directory . Just try to understand it.



Code:
import java.io.File;
 public class CurrentWorkingDirectory {
   public static void main (String args[]) {
     File directorys = new Files (".");
     try {
       System.out.println ("Current directory's path: " 
            + directorys.getCanonicalPath()); 
       System.out.println ("Current directory's virtual path: " 
            + directorys.getAbsolutePath());
     }catch(Exception es) {
       System.out.println("Exceptione iss ="+es.getMessage());
      }
     }
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to get operating system temporary directory using java program?"
Thread Thread Starter Forum Replies Last Post
Gentoo operating system vs Debian operating system. DEWITT Operating Systems 4 04-01-2010 11:49 PM
Creating an operating system (OS) in Java Shaan12 Software Development 3 29-10-2009 11:51 PM
How to remove temporary program files chaosblade Operating Systems 3 30-07-2009 12:09 PM
Could not access program in two operating system msi_1985 Operating Systems 5 12-03-2009 09:10 PM
Best Antivirus Program for 64 bit operating system Bhagwandas Networking & Security 6 19-01-2009 04:39 PM


All times are GMT +5.5. The time now is 09:50 AM.