import java.io.File;
import java.io.FilenameFilter;
public class MyFile{
public static void main(String[] args) throws Exception{
String path="C:\\images";
//String path="C:/images";
String[] jpgFile=(new File(path)).list(new MyExtFilter("jpg"));
System.out.println(jpgFile);
for(String filename:jpgFile){
System.out.println(filename);
}
}
static class MyExtFilter implements FilenameFilter{
private String ext;
MyExtFilter(String ext){
this.ext=ext;
}
public boolean accept(File dir, String name){
return name.endsWith(ext);
}
}
}
java获取指定目录指定类型文件
最新推荐文章于 2024-06-30 03:24:02 发布