当前位置:网站首页>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());
}
}
}
边栏推荐
猜你喜欢
随机推荐
使用Protege4和CO-ODE工具构建OWL本体的实用指南-1.3版本(4.Building An OWL Ontology)
软件测试的流程规范有哪些?具体要怎么做?
软件测试面试常见问题及答案(发散思维、接口、性能、概念、)
恶意软件查杀工具分享
MySQL Leak Detection and Filling (2) Sorting and Retrieval, Filtering Data, Fuzzy Query, Regular Expression
全网最全的软件测试基础知识整理(新手入门必学)
这12个GIS软件一个比一个好用
LPP代码及其注释
软件测试个人求职简历该怎么写,模板在这里
MySQL索引
Do you know the basic process and use case design method of interface testing?
银联最新测试工程师笔试题目,你能得多少分?
MVCC多版本并发控制
Domestic with Google earth software, see the download 19th level high-resolution satellite images so easy!
第三方免费开放API 获取用户IP 并查询其地理位置
These 12 GIS software are better than the other
性能测试包括哪些方面?分类及测试方法有哪些?
运行flutter项目时遇到的问题
白盒测试的概念、目的是什么?及主要方法有哪些?
Another implementation of lateral view explode









