File.listFiles(FileFilter filter) has the following syntax.
public File [] listFiles(FileFilter filter)
In the following code shows how to use File.listFiles(FileFilter filter) method.
/*from w w w . j a v a2 s . com*/ import java.io.File; import java.io.FileFilter; public class Main { public static void main(String[] args) { File f = new File("c:/test"); FileFilter filter = new FileFilter() { @Override public boolean accept(File pathname) { return pathname.isFile(); } }; // returns pathnames for files and directory File[] paths = f.listFiles(filter); for (File path : paths) { System.out.println(path); } } }
The code above generates the following result.