pro.shuangxi.utils.FileUtils Maven / Gradle / Ivy
package pro.shuangxi.utils;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
/**
* @author mengshx
* 文件相关工具类
* datetime 2022-07-15 11:00
**/
public class FileUtils {
public static List getFileRelativePath(File directory, String suffix) {
List pathList = new ArrayList<>();
getPath(pathList, "", directory,suffix);
return pathList;
}
private static void getPath(List pathList, String path, File directory,String suffix) {
for (File file : directory.listFiles()) {
if (file.isDirectory()) {
getPath(pathList,path+file.getName()+File.separator,file,suffix);
}else {
if (file.getName().contains(suffix)) {
pathList.add(path + file.getName());
}
}
}
}
}