Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find "My Documents" folder in Java

Tags:

java

windows

I'm willing to save a file in the user's "My Documents" folder.

I tried getting the location like this :

System.getenv("USERPROFILE") + "\\My Documents\\"

Then, I realized this wouldn't work in a system where the language is set to another language, french for example.

Is there another way of getting the "My Documents" folder efficiently?

like image 845
Attilah Avatar asked Oct 01 '09 12:10

Attilah


Video Answer


1 Answers

Regarding performance, this is faster than using JFileChooser:

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

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

like image 183
IvanRF Avatar answered Oct 09 '22 07:10

IvanRF