Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: Find .txt files in specified folder [closed]

Tags:

java

file

Is there a built in Java code that will parse a given folder and search it for .txt files?

like image 676
Sri Avatar asked Sep 06 '09 05:09

Sri


1 Answers

You can use the listFiles() method provided by the java.io.File class.

import java.io.File; import java.io.FilenameFilter;  public class Filter {      public File[] finder( String dirName){         File dir = new File(dirName);          return dir.listFiles(new FilenameFilter() {                   public boolean accept(File dir, String filename)                       { return filename.endsWith(".txt"); }         } );      }  } 
like image 62
djna Avatar answered Sep 18 '22 13:09

djna