Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JFileChooser

 
donepudi madhu
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic