• Post Reply Bookmark Topic Watch Topic
  • New Topic

retrieving files with particular extensions  RSS feed

 
sanj singh
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All
I am trying to retrieve files with particular extensions like .html or .jpg etc.Can anybody guide me as to how to do it?

regards
sanj
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<pre>
public static File[] list(File directory, String suffix) throws IOException {
final String lowerSuffix = suffix.toLowerCase();
FileFilter filter =
new FileFilter() {
public boolean accept(File file) {
return file.getName().toLowerCase().endsWith(lowerSuffix);
}
};
return directory.listFiles(filter);
}</pre>
This assumes that you want to ignore the case of the suffix - list .EXE as well as .exe (and even .eXe if any exist.) If this is undesireable, remove the toLowerCase() calls.
 
M.Aamir khan
Greenhorn
Posts: 11
Netbeans IDE Python VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sanj singh wrote:Hi All
I am trying to retrieve files with particular extensions like .html or .jpg etc.Can anybody guide me as to how to do it?


The old Way :




Modern and Concise Way :


 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!