Home Java Java-get-example Java program to get the desktop Path



Java program to get the desktop Path
Posted on: October 24, 2008 at 12:00 AM
In this example program we have to get the desktop path of the system. In the java environment we can get the desktop path also with the system's property.

Java program to get the desktop Path

     

In this example program we have to get the desktop path of the system. In the java environment we can get the desktop path also with the system's property. For getting the desktop path we have to add the "/Desktop" string into the property value of user.home.

Here is the full example code of GetDesktopPath.java as follows:

 

 

 

GetDesktopPath.java

import java.util.*;
import java.lang.*;
import java.net.*;

public class GetDesktopPath
{
  public static void main(String args[]) {
  try{
  String desktopPath = System.getProperty("user.home""/Desktop";
  System.out.print(desktopPath.replace("\\""/"));
  }catch (Exception e){
  System.out.println("Exception caught ="+e.getMessage());
  }
  }
}

 

Output:

C:\javaexamples>javac GetDesktopPath.java

C:\javaexamples>java GetDesktopPath
C:/Documents and Settings/Administrator/Desktop
C:\javaexamples>

 

Download Source Code

 

Related Tags for Java program to get the desktop Path:
javacstringpathpropertyusergetsystemenvironmentvivalueintthisforexampleaddwithprogramtoramexamtopeitdeshomelscanusepeinmnttrcaddjadesdeskemmeintoproenvsysxaxampssoatkisirironhamplproperstrrtropevattssriringthavstalulsopleplproppronomogro


More Tutorials from this section

Ask Questions?    Discuss: Java program to get the desktop Path   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.