Share this page 

Get the Windows "My Documents" pathTag(s): Environment


This value is stored in the registry and there is no easy way to get it with regular Java unless you execute an external utility, see this HowTo.

As an alternative, we can use a method provided by the JFileChooser class.

import javax.swing.JFileChooser;
javax.swing.filechooser.FileSystemView;

public class GetMyDocuments {
  public static void main(String args[]) {
     JFileChooser fr = new JFileChooser();
     FileSystemView fw = fr.getFileSystemView();
     System.out.println(fw.getDefaultDirectory());
  }
}

See also Get Windows Special Folders (JNA)