package com.heima.test;
import java.io.File;
import java.io.FilenameFilter;
public class Demo3_Test {
/**
** public String[] list(FilenameFilter filter)
* public File[] listFiles(FileFilter filter)
*/
public static void main(String[] args) {
File f = new File("/E://");
String[] arr = f.list(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
File f1 = new File(dir, name);
return f1.isFile() && f1.getName().endsWith(".jpg");
}
});
for (String string : arr) {
System.out.println(string);
}
}
}
|
|