Get the Windows "My Documents" path

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());
  }
}



If you find this article useful, consider making a small donation
to show your support for this Web site and its content.

Written and compiled by Réal Gagnon ©1998-2010
[ home ]