Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

FileFilter() accepts if File.isDirectory()  RSS feed

 
Jon Camilleri
Ranch Hand
Posts: 664
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why does the code snippet accept when f.isDirectory() == true, since it intends to select files ending with ".xml"?




Source Core Java Vol I (8th Ed) Listing 10-7. P.541
 
Stephan van Hulst
Saloon Keeper
Posts: 7817
142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because you want the file chooser to display folders as well, since you want to be able to browse through directory structures.
 
Rob Spoor
Sheriff
Posts: 21092
85
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without the "|| f.isDirectory()" part you will see only XML files in the current folder. No other files, but also no sub folders. That makes it hard to navigate. The JFileChooser will make sure that it will not allow actual selection of directories if you've set its mode correctly (by default it allows only selection of files so that's usually good already).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!