方式一
public class ZuoYe1 {
public static void main(String[] args) {
File file=new File("E:\\java\\黑马20151015\\day19");
String[] list = file.list();
for(String str:list){
if(str.endsWith(".mp4")){
System.out.println(str);
}
}
}
}
方式二
package zuoye;
import java.io.File;
public class ZuoYe {
public static void main(String[] args) {
File file=new File("E:\\java\\黑马20151015\\day19");
File[] f=file.listFiles();
for(File f1:f){
if(f1.getName().endsWith(".mp4")){
System.out.println(f1.getName());
}
}
}
}
方式三
package zuoye;
import java.io.File;
import java.io.FilenameFilter;
public class ZuoYe2 {
public static void main(String[] args) {
File file=new File("E:\\java\\黑马20151015\\day19");
String[] str=file.list(new FilenameFilter() {
public boolean accept(File dir, String name) {
File f=new File(dir,name);
boolean flag=f.isFile();
boolean flag1=f.getName().endsWith(".mp4");
return flag&&flag1;
}
});
for(String s:str){
System.out.println(s);
}
}
} |