Java: Find .txt files in specified folder

file, java

Solution

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"); }
        } );

    }

}

Problem

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

Original source

Related problems