Results 1 to 5 of 5

Thread: How to get operating system temporary directory using java program?

  1. #1
    Join Date
    Aug 2009
    Posts
    57

    How to get operating system temporary directory using java program?

    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.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    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);
        }
    }

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    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"));
        }
    }

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    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

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    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());
          }
         }
    }

Similar Threads

  1. Gentoo operating system vs Debian operating system.
    By DEWITT in forum Operating Systems
    Replies: 4
    Last Post: 05-01-2010, 12:49 AM
  2. Creating an operating system (OS) in Java
    By Shaan12 in forum Software Development
    Replies: 3
    Last Post: 29-10-2009, 11:51 PM
  3. How to remove temporary program files
    By chaosblade in forum Operating Systems
    Replies: 3
    Last Post: 30-07-2009, 12:09 PM
  4. Could not access program in two operating system
    By msi_1985 in forum Operating Systems
    Replies: 5
    Last Post: 12-03-2009, 09:10 PM
  5. Best Antivirus Program for 64 bit operating system
    By Bhagwandas in forum Networking & Security
    Replies: 6
    Last Post: 19-01-2009, 05:39 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,710,845,507.03071 seconds with 16 queries