Getting My Documents path in Java

后端 未结 8 1303
孤城傲影
孤城傲影 2020-12-06 04:21

I need to find my documents path using Java. The following code doesn\'t give me \"accurate\" loation

System.getProperty(\"user.home\");

What sh

8条回答
  •  爱一瞬间的悲伤
    2020-12-06 04:53

    Since the most upvoted answer from @xchiltonx uses JFileChooser I would like to add that, regarding performance, this is faster than using JFileChooser:

    FileSystemView.getFileSystemView().getDefaultDirectory().getPath()
    

    In my PC, JFileChooser aproach needed 300ms, and calling FileSystemView directly needed less than 100ms.

    Note: The question is a possible duplicate of How to find “My Documents” folder in Java

提交回复
热议问题