-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSolution.java
More file actions
98 lines (64 loc) · 2.94 KB
/
Solution.java
File metadata and controls
98 lines (64 loc) · 2.94 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//But now I go my way to him that sent me; and none of you asketh me, Whither goest thou? (John 16:5)
package com.javarush.task.task31.task3104;
import java.io.File;
import java.io.IOException;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
/*
Поиск скрытых файлов
*/
public class Solution extends SimpleFileVisitor<Path> {
public static void main(String[] args) throws IOException {
EnumSet<FileVisitOption> options = EnumSet.of(FileVisitOption.FOLLOW_LINKS);
final Solution solution = new Solution();
Files.walkFileTree(Paths.get("D:/"), options, 20, solution);
List<String> result = solution.getArchived();
System.out.println("All archived files:");
for (String path : result) {
System.out.println("\t" + path);
}
List<String> failed = solution.getFailed();
System.out.println("All failed files:");
for (String path : failed) {
System.out.println("\t" + path);
}
}
private List<String> archived = new ArrayList<>();
private List<String> failed = new ArrayList<>();
public List<String> getArchived() {
return archived;
}
public List<String> getFailed() {
return failed;
}
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
String fileName = file.getFileName().toString();
if (fileName.endsWith(".zip") || fileName.endsWith(".rar")) {
archived.add(file.toString());
}
return super.visitFile(file, attrs);
}
@Override
public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
failed.add(file.toString());
return FileVisitResult.SKIP_SUBTREE;
}
}
/*
Поиск скрытых файлов
В классе Solution переопредели логику двух методов:
- visitFile кроме своей логики должен добавлять в archived все пути к zip и rar файлам
- visitFileFailed должен добавлять в failed все пути к недоступным файлам и возвращать SKIP_SUBTREE
Пример вывода:
D:/mydir/BCD.zip
Метод main не участвует в тестировании
Требования:
1. В классе Solution нужно переопределить метод visitFile.
2. Метод visitFile, кроме своей логики, должен добавлять в поле archived все пути к zip и rar файлам.
3. В классе Solution нужно переопределить метод visitFileFailed.
4. Метод visitFileFailed должен добавлять в поле failed все пути к недоступным файлам и возвращать SKIP_SUBTREE.
*/