Sri Sri - 1 year ago 135
Java Question

Java: Find .txt files in specified folder

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


Answer Source

You can use the listFiles() method provided by the class;


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


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download