-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyFileVisitor.java
More file actions
36 lines (33 loc) · 1.03 KB
/
Copy pathMyFileVisitor.java
File metadata and controls
36 lines (33 loc) · 1.03 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
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
class MyFileVisitor extends SimpleFileVisitor<Path> {
boolean isFind = false;
Path nameFile;
public MyFileVisitor(Path nameFile) {
this.nameFile = nameFile;
}
@Override
public FileVisitResult visitFileFailed(Path dir, IOException e) throws IOException {
return FileVisitResult.SKIP_SUBTREE;
}
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
if (Files.isExecutable(file)) {
if (file.endsWith(nameFile)) {
this.nameFile = file;
this.isFind = true;
return FileVisitResult.TERMINATE;
}
else {
return FileVisitResult.CONTINUE;
}
}
else {
return FileVisitResult.SKIP_SUBTREE;
}
}
}