get Files by extension from a directory - Android java.io

Android examples for java.io:Directory

Description

get Files by extension from a directory

Demo Code

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class Main{

    protected static List<File> getFiles(File dir, String extension) {
        List<File> files = new ArrayList<File>();

        for (File f : dir.listFiles()) {
            if (f.getName().endsWith(extension))
                files.add(f);//w  ww . ja  v  a2  s . co m
        }

        return files;
    }

}

Related Tutorials