更新读取

main
linbin 2024-08-26 15:19:13 +08:00
parent 42c6bc343d
commit 1273de144a
1 changed files with 33 additions and 0 deletions

View File

@ -0,0 +1,33 @@
package org.example;
import java.io.File;
import java.util.LinkedList;
import java.util.List;
public class ReadDirDile
{
public static void main(String[] args)
{
String path = "/Users/linbin/SynologyDrive/附件/426";
File dir = new File(path);
List<String> list = new LinkedList<>();
readDir(dir, list);
list.stream().map(str -> " - "+str.substring(path.length() + 1)).forEach(System.out::println);
}
public static void readDir(File dir, List<String> list)
{
File[] files = dir.listFiles();
for (File file : files)
{
if (file.isDirectory())
{
readDir(file, list);
}
else
{
list.add(file.getAbsolutePath());
}
}
}
}