• Post Reply Bookmark Topic Watch Topic
  • New Topic

How Do I Use FilenameFilter?

 
ernest fakudze
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi to all!
I have looked at the JDK documentation and learned that FilenameFilter is an interface. I want to write a program which selects files of a particular type from a directory. How do I associate a File Objet with FilenameFilter?
e.g. if File myFile= new File("c:\\myDir");
then I do myFile.list()
How can i then list all the .txt files only in my directory?
Please help me or my boss is going to kill me if I don't get this done by the end of the week!
Thanks in advance.
 
Rowan Brownlee
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ernest
http://www.javaranch.com/ubb/Forum33/HTML/004150.html
Here's an example I wrote for someone wanting to read url files from a directory, but you could do something similar for files ending in a .txt extension. It includes implementation of FilenameFilter.
cheerio
rowan
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!