JFileChooser change default directory in Windows

dumazy picture dumazy · Nov 22, 2012 · Viewed 57.4k times · Source

I want to change the default directory of my JFileChooser to "My Music" on Windows. This directory is C:\Users\Fre\Music on my account because my username is Fre

The default is set on C:\Users\Fre\Documents (depends on OS i think). How can I change this?

Answer

Juvanis picture Juvanis · Nov 22, 2012

You can use the API method setCurrentDirectory when initializing your JFileChooser objects:

public void setCurrentDirectory(File dir)

Sample usage might be like:

yourFileChooser.setCurrentDirectory(new File  
(System.getProperty("user.home") + System.getProperty("file.separator")+ "Music"));