• Post Reply Bookmark Topic Watch Topic
  • New Topic

Read a folder to filter files.  RSS feed

 
Alexandre Mendes
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am creating an application, but can not perform a reading from a folder and filter the files you want. I am using the File class java.io.File package, this class and right for this type of work or have another class to filter out any files you want?




 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use the listFiles() method on the folder and check against the file names returned.
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or use an overload of listFiles() that accepts a FileFilter / FilenameFilter implementation that only accepts the files you're interested in.
 
Rajat Jindal
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Above solutions are good enough... I will put that in other way..

FileFilter is an interface, it has one method with signatures as


just implement this method by providing the logic for type of the file you are looking for say .exe . Use method getName() to implement the logic.
But one more thing don't forget to check whether this fileName is really a file or its a directory.

Check API http://docs.oracle.com/javase/6/docs/api/java/io/File.html
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!