import java.io.File;
public class FileTest {
public static void main(String[] arg) {
String filePath = "F:\\";
Long num = 0L;
num = getFiles(filePath);
System.out.println(filePath + "___有____" + num + "___个文件___");
}
public static Long getFiles(String filePath) {
Long fileNumber = 0L;
File file = new File(filePath);
if (file.exists()) {
if (file.isDirectory()) {
File[] listFiles = file.listFiles();
System.out.println(filePath + "中有" + listFiles.length + "个文件夹");
for (File file2 : listFiles) {
fileNumber = fileNumber + getFiles(file2.getPath());
}
return fileNumber;
}
else {
System.out.println("文件:" + file.getPath());
return 1L;
}
}
return fileNumber;
}
}
根据路径查找所有文件
最新推荐文章于 2023-07-09 20:51:36 发布