更新读取
parent
42c6bc343d
commit
1273de144a
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue