Java DirectoryStream .Filter .accept (T entry)
Syntax
DirectoryStream.Filter.accept(T entry) has the following syntax.
boolean accept(T entry) throws IOException
Example
In the following code shows how to use DirectoryStream.Filter.accept(T entry) method.
//w w w.ja v a2s. c o m
import static java.nio.file.LinkOption.NOFOLLOW_LINKS;
import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class Main {
public static void main(String[] args) {
Path path = Paths.get("C:/tutorial/Java/JavaFX");
DirectoryStream.Filter<Path> dir_filter = new DirectoryStream.Filter<Path>() {
public boolean accept(Path path) throws IOException {
return (Files.isDirectory(path, NOFOLLOW_LINKS));
}
};
try (DirectoryStream<Path> ds = Files.newDirectoryStream(path, dir_filter)) {
for (Path file : ds) {
System.out.println(file.getFileName());
}
} catch (IOException e) {
System.err.println(e);
}
}
}