-
Notifications
You must be signed in to change notification settings - Fork 205
Expand file tree
/
Copy pathTask02Main.java
More file actions
31 lines (24 loc) · 1.17 KB
/
Task02Main.java
File metadata and controls
31 lines (24 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package com.example.task02;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class Task02Main {
public static void main(String[] args) throws IOException, InterruptedException {
//здесь вы можете вручную протестировать ваше решение, вызывая реализуемый метод и смотря результат
// например вот так:
System.out.println(listFiles(Paths.get("task02/src/main/resources/")));
}
public static List<Path> listFiles(Path rootDir) throws IOException, InterruptedException {
if (!Files.exists(rootDir) || !Files.isDirectory(rootDir)) {
throw new IllegalArgumentException("Указанный путь не является существующей директорией: " + rootDir);
}
try (Stream<Path> paths = Files.walk(rootDir)) {
return paths.filter(Files::isRegularFile).collect(Collectors.toList());
}
}
}