file count of .txt Java [closed]

import java.io.File;
import java.io.FilenameFilter;

public class FileCountFilter {

public File[] findFilesInDir(String dirName){
    File dir = new File(dirName);

    return dir.listFiles(new FilenameFilter() { 
             public boolean accept(File dir, String filename)
                  { return filename.toLowerCase().endsWith(".txt"); }
    } );

}

}

The Length of File[] returned by findFilesInDir method would be what you are looking for.

Leave a Comment