package com.hg.audioserver.utils;
import com.hg.base.utils.QueryFilter;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
/**
* @author dhy
*/
public class FileUtil {
public static List<String> list = new ArrayList<>();
public static void getList(String patha){
String path=patha;
File file=new File(path);
File[] tempList = file.listFiles();
System.out.println("该目录下对象个数:"+tempList.length);
for (int i = 0; i < tempList.length; i++) {
if (tempList[i].isFile()) {
System.out.println("文件:"+tempList[i]);
}
if (tempList[i].isDirectory()) {
list.add(tempList[i].getPath());
System.out.println("文件夹:"+tempList[i].getPath());
//递归:
getList(tempList[i].getPath());
}
}
}
public static void main(String[] args) {
getList("文件夹路径");
System.out.println(list);
}
}
java获取文件夹下所有目录
于 2022-04-11 18:58:27 首次发布