File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import java.io.IOException;
2+ import java.nio.file.DirectoryStream;
3+ import java.nio.file.*;
4+ import java.nio.file.Files;
5+ import java.nio.file.Path;
6+ import java.nio.file.Paths;
7+ import java.util.ArrayList;
8+ import java.util.List;
9+
10+ public class dd {
11+
12+ private static List<Path> paths = new ArrayList<>();
13+
14+ private static List<Path> walk(Path path) throws IOException {
15+
16+ try (DirectoryStream<Path> stream = Files.newDirectoryStream(path))
17+ {
18+ Path dummy = Paths.get(" ");
19+
20+ for (Path entry : stream) {
21+ if (Files.isDirectory(entry)) {
22+ paths.add(entry.getFileName());
23+ paths.add(dummy);
24+ walk(entry);
25+
26+ }
27+ else if (Files.isRegularFile(entry)){
28+ paths.add(entry.getFileName());
29+ }
30+
31+ }
32+ }
33+
34+ return paths;
35+ }
36+
37+
38+ public static void main(String[] args) throws IOException {
39+
40+ Path myPath = Paths.get("D:\\folder");
41+
42+
43+ List<Path> paths = walk(myPath);
44+
45+
46+
47+
48+ paths.forEach(path -> System.out.println(path));
49+ }
50+ }
You can’t perform that action at this time.
0 commit comments