This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes JFileChooser Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JFileChooser " Watch "JFileChooser " New topic
Author

JFileChooser

donepudi madhu
Greenhorn

Joined: Sep 25, 2002
Posts: 11
Can we select a directory from a JFileChooser and read the contents of the directory file by file? If so please tell me how.
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Yes...

Make sure you make directories selectable in JFileChooser by calling setFileSelectionMode( JFileChooser.DIRECTORIES_ONLY ), and setting an appropriate FileFilter (one that only returns true if file.isDirectory() ) using setFileFilter( FileFilter ).

Once you get a selection back from the JFileChooser, you can call file.list() to get a String array of file names, or file.listFiles() to get a File array.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
 
 
subject: JFileChooser