定义需要读取的文件夹,放在一个方法中
public static void readMore() throws IOException {
\\ 读取的文件夹
File file = new File("C:\\Users\\DELL\\Desktop\\henan\\data\\");
\\ 输出的文件夹
String destFiles = "C:\\Users\\DELL\\Desktop\\henan\\back\\access\\西6市1.1\\程序处理数据\\";
\\ 传参调用处理方法
printAllDir(file, 5, destFiles);
}
处理方法如下:
public static void printAllDir(File file, int depth, String destFiles) throws IOException {
if (file.isDirectory()) {
for (File listFile : file.listFiles()) {
// 如果还是文件夹则继续调用判断,深度+1
printAllDir(listFile, depth + 1, destFiles);
}
} else { // 读取到的是文件则进行对文件处理
String fileNames = file.getName();
String fileName = fileNames.substring(0,fileNames.lastIndexOf("."));
System.out.println("文件名==