1、代码
package com.sm2005a;
import org.junit.jupiter.api.Test;
import java.io.File;
public class ListAllFileTests {
public void listAllFile(String path) {
File fileFold = new File(path);
File[] files = fileFold.listFiles();
for (File f : files) {
if(f.isDirectory()) {
// 如果是目录
listAllFile(f.getAbsolutePath());
}
else {
// 如果是文件
System.out.println("FILE:"+f.getAbsolutePath());
String fileName = f.getAbsolutePath();
// 判断扩展名
if(fileName.lastIndexOf(".") != -1 && fileName.lastIndexOf(".") != 0) {
String extName = fileName.substring(fileName.lastIndexOf("."));
if(extName.equalsIgnoreCase(".mp4")) {
System.out.println("Video File:"+f.getAbsolutePath());
}
}
}
}
}
@Test
public void listPath() {
listAllFile("E:\\videos");
}
}