当前位置:网站首页>7.FileFilter接口
7.FileFilter接口
2022-08-09 09:23:00 【过来我的小熊】
FileFilter接口
- public interface FileFilter
- boolean accept(File pathname)
- 当调用File类中listFIles()方法时,支持传入FileFilter接口的接口实现类,对获取文件进行过滤,只有满足条件的文件才可以出现在listFiles()的返回值中
package com.io.file;
import java.io.File;
import java.io.FileFilter;
/**
* FileFilter接口的使用
*/
public class Demo2 {
public static void main(String[] args) {
// 创建File对象
File dir = new File("E:\\桌面\\img");
// 使用文件过滤器
File[] files = dir.listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
if (pathname.getName().endsWith(".png")){
return true;
}
return false;
}
});
// 遍历文件数组
for (File file : files) {
System.out.println(file.getName());
}
}
}
边栏推荐
- Lecture 4 SVN
- Summary of steps and methods for installing and uninstalling test cases that you must read
- 一个项目的整体测试流程有哪几个阶段?测试方法有哪些?
- 中国打造国产“谷歌地球”清晰度吓人
- unittest测试框架原理及测试流程解析,看完绝对有提升
- How much do you know about the mobile APP testing process specifications and methods?
- Ontology Development Diary 01-Jena Configuration Environment Variables
- 功能自动化测试实施的原则以及方法有哪些?
- Max Flow P
- 迭代
猜你喜欢
随机推荐
选择黑盒测试用例设计方法的综合策略方案总结
Read file by byte and character_load configuration file
unix环境编程学习-多线程
What are the basic concepts of performance testing?What knowledge do you need to master to perform performance testing?
[Environmental Construction] tensorrt
米斗APP逆向分析
TestNG使用教程详解
软件测试面试中,面试官问你一些比较“刁难”的问题你会怎么回答
谷歌地图时代结束,怎么看高清卫星影像地图?
Redis Basics
MySQL事务隔离
Environment build onnxruntime 】
第四讲 SVN
Teach you how to get a 0.1-meter high-precision satellite map for free
.equals ==
MVCC多版本并发控制
字典
HD Satellite Map Browser
运行flutter项目时遇到的问题
JMeter参数化4种实现方式









