• Post Reply Bookmark Topic Watch Topic
  • New Topic

FileFilter() accepts if File.isDirectory()

 
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
Bartender
Posts: 6583
84
  • 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: 20817
68
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).
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!