仅接受隐藏文件/目录的过滤器:
import java.io.IOException;//来 自 时 代 J a v a 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:/folder1/folder2/folder4"); DirectoryStream.Filter<Path> hidden_filter = new DirectoryStream.Filter<Path>() { public boolean accept(Path path) throws IOException { return (Files.isHidden(path)); } }; System.out.println("\nUser defined filter applied:"); try (DirectoryStream<Path> ds = Files.newDirectoryStream(path, hidden_filter)) {