How to Get the Desktop Path in Java

Desktop path for file output Java

File desktop = new File(System.getProperty("user.home"), "Desktop");

Get absolute desktop path

If you want to get the result of the method getCurrentUserDesktopPath() in your Mover class, you just need to put this line in your main method:

String desktopPath = WindowsUtils.getCurrentUserDesktopPath();

As this method is made static you don't need to declare a WindowsUtils object.

Get desktop path with groovy

To get your desktop path in Groovy you can use your Java code directly, since it works perfectly:

String userHomeFolder = System.getProperty("user.home") + "/Desktop";

If you want an alternative a Groovy way to do so could be:

String userHomeFolder = System.properties['user.home'] + "/Desktop"

Or:

String userHomeFolder = System.properties.'user.home' + "/Desktop"

All of this gets the same result.

In java under Windows, how do I find a redirected Desktop folder?

FileSystemView filesys = FileSystemView.getFileSystemView();

filesys.getHomeDirectory()


Related Topics



Leave a reply



Submit