仅接受大于200KB的文件/目录的过滤器:
import java.io.IOException; import java.nio.file.DirectoryStream;// 来自 NowJava.com 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:/folder1/folder2/folder4"); DirectoryStream.Filter<Path> size_filter = new DirectoryStream.Filter<Path>() { public boolean accept(Path path) throws IOException { return (Files.size(path) > 204800L); } }; System.out.println("\nUser defined filter applied:"); try (DirectoryStream<Path> ds = Files.newDirectoryStream(path, size_filter)) { for (