如题所述
import java.io.File;
import java.io.FileFilter;
public class FileDemo {
public static void main(String[] args) throws Exception {
File dir = new File("文件路径");
getFilter(dir,"过滤内容");
}
public static void getFilter(File dir,String s) {//过滤自定义后缀名
final String ss=s;
File[] files=dir.listFiles(new FileFilter() {
public boolean accept(File file) {
if (file.isDirectory()) {
getFilter(file,ss);
}
return file.getName().contains(ss);
}
});
for (File file : files) {
System.out.println(file.getAbsolutePath());
}
}
import java.io.FileFilter;
public class FileDemo {
public static void main(String[] args) throws Exception {
File dir = new File("文件路径");
getFilter(dir,"过滤内容");
}
public static void getFilter(File dir,String s) {//过滤自定义后缀名
final String ss=s;
File[] files=dir.listFiles(new FileFilter() {
public boolean accept(File file) {
if (file.isDirectory()) {
getFilter(file,ss);
}
return file.getName().contains(ss);
}
});
for (File file : files) {
System.out.println(file.getAbsolutePath());
}
}
温馨提示:答案为网友推荐,仅供参考