java.io.FilenameFilter
is an interface that declares single method,
public boolean accept(File directory, String filename)
The method should return true
if the file passes through the filter and false
if it doesn't.
FilenameFilter
is an interface, you must implement it in a class. Here is an example class which filters out everything that is not a java source code file.
import java.io.*;
public class JavaFilter implements FilenameFilter {
public boolean accept(File directory, String filename) {
if (filename.endsWith(".java")) return true;
return false;
}
}
public boolean accept(File directory, String filename) {
if (filename.endsWith(".java") && directory.canWrite()) return true;
return false;
}