一、获取指定路径下的所有Excel文件
package com.boulderaitech.utils;
import java.io.File;
import java.util.Arrays;
public class FileUtil {
public static void main(String[] args) {
String path = "C:\\Users\\xxljob\\Desktop\\sage字段表";
// Arrays.stream(getFileNameArray(new File(path))).forEach(System.out::println);
Arrays.stream(getFileNameArray(new File(path))).forEach(x->{
String[] replacedPath = x.replace('\\', '@').split("@");
String fileName = replacedPath[replacedPath.length - 1];
String fileNameWithoutSuffix = fileName.split(".xlsx")[0];
System.out.println(fileNameWithoutSuffix);
});
}
public static String[] getFileNameArray(File file) {
return Arrays.stream(file.listFiles(pathname -> pathname.isFile())).map(x -> String.valueOf(x)).toArray(String[]::new);
}
}
二、获取路径下的文件和文件夹
思路:递归
参考:https://www.csdn.net/tags/Mtjakg3sNzY3NTUtYmxvZwO0O0OO0O0O.html
标签:Java,String,stream,Arrays,public,文件夹,File,FileUtils,replacedPath From: https://www.cnblogs.com/liujinhui/p/16644183.html