Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to use the FilenameFilter interface  RSS feed

 
kay lin
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi:
This is regarding my previous post,

if I want to include all the xml files in a directy and its sub directory
, say C:\test,

do i just do the following



plz let me know

Many thanks.
 
Elihu Smails
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just write a class that implements FileFilter. Then create a method called accept that takes in a File object and returns a boolean. Inside this method, test the extension. If the extension is ".xml", return true, otherwise, return false.

This is all in the java tutorial...
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!