集册 Java实例教程 只接受大于200KB的文件/目录的筛选器:

只接受大于200KB的文件/目录的筛选器:

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

426
仅接受大于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 (
展开阅读全文