集册 Java实例教程 只接受隐藏文件/目录的筛选器:

只接受隐藏文件/目录的筛选器:

欢马劈雪     最近更新时间:2020-01-02 10:19:05

590
仅接受隐藏文件/目录的过滤器:

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)) {

      
展开阅读全文