How to get desktop path in java

There two ways to achieve this:

  1. By using user.home property
    String path = System.getProperty("user.home") + File.separator +"Desktop";
  2. By using FileSystemview
    FileSystemView view = FileSystemView.getFileSystemView();
    File file = view.getHomeDirectory();
    String path = file.getPath();

Leave a Reply

Your email address will not be published. Required fields are marked *