How to Get the Desktop Path in Java
How to Get the Desktop Path in Java
One of the most common questions when it comes to working with Java is how to get the desktop path. Getting the desktop path can be incredibly helpful for many applications, such as saving files, loading data and more. Fortunately, getting the desktop path isn’t too difficult and can be accomplished with a few lines of code.
Finding the Desktop Path on Windows
To get the desktop path on Windows, you can use the following code snippet:
String desktopPath = System.getProperty("user.home") + "/Desktop";
This will get the user’s home directory, as specified by the “user.home” system property, and add the “/Desktop” string at the end. This should give you the full path to the user’s desktop folder.
Finding the Desktop Path On Mac OSX
On Mac OSX, you can use the following line to get the desktop path:
String desktopPath = System.getProperty("user.home") + "/Desktop";
Just like on Windows, this will get the user’s home directory, as specified by the “user.home” system property, and add the “/Desktop” string at the end. This should give you the full path to the user’s desktop folder.
Wrapping Up
In this tutorial, we showed you how to get the desktop path in Java, both on Windows and Mac OSX. We hope that this has been helpful in getting you started with your project!