Java递归扫描文件路径

时间:2023-03-09 21:37:26
Java递归扫描文件路径
import java.io.File;

public class Test {

    public static int count = 0;

    public static void main(String[] args){
String path = "G:/Document/HongDaXingYe/Project/oa/workflow/home/weaver/ecology/workflow/";
// String path = "G:/Document/HongDaXingYe/Project/oa/workflow/home/weaver/ecology/workflow/mode/";
File file = new File(path);
File[] files = file.listFiles();
getFiles(files);
System.out.println(count);
} public static void getFiles(File[] files){
for(File file : files){
count++;
if(file.isDirectory()){
getFiles(file.listFiles());
}else{
System.out.println("file path:" + file.getAbsolutePath());
}
}
} }

直接上代码,路径改成你们要的文件夹路径就好了.