当前位置:网站首页>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());
}
}
}
边栏推荐
猜你喜欢
随机推荐
MySQL Leak Detection and Filling (3) Calculated Fields
【分布式事务】
第四讲 SVN
MySQL事件_单次事件_定时循环事件
.equals ==
功能自动化测试实施的原则以及方法有哪些?
运行flutter项目时遇到的问题
Web请求原理
有返回值的函数
年薪40W测试工程师成长之路,你在哪个阶段?
Anti App so层对抗分析
性能测试报告包括哪些内容?模板范文哪里找?看这里
MySQL事务隔离
Lecture 4 SVN
Venture DAO Industry Research Report: Macro and Classic Case Analysis, Model Summary, Future Suggestions
Ovie map computer terminal and mobile terminal can not be used, is there any alternative map tool
接口测试主要测试哪方面?需要哪些技能?要怎么学习?
网络安全入门基础:IP地址
Sweet alert
oracle查看表空间占用情况并删除多余表所占空间