View the Exhibit:
Given the following code fragment:
<code>
class Finder extends SimpleFileVisitor<Path> {
private final PathMatcher matcher;
private static int numMatches = 0;
Finder() {
matcher = FileSystems.getDefault().getPathMatcher(“glob:*java”);
}
void find(Path file) {
Path Name = file.getFileName();
if (name != null && matcher.matches(name)) {
numMatches++;
}
}
void report()
{
System.out.println(“Matched: ” + numMatches);
}
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
find(file);
return CONTINUE;
}
}
public class Visitor {
public static void main(String[] args) throws IOException {
Finder finder = new Finder();
Files.walkFileTree(Paths.get(“d:\\Project”), finder);
finder.report();
}
}
</code>
What is the result?
A.
Compilation fails
B.
6
C.
4
D.
1
E.
3
Explanation:
The program will compile and run.
Referring to the exhibit there will be six nodes that matches glob:*java.
C
+1 C
+2 C
i sow a post on stackoverflow says :
Files.walkFileTree(Paths.get(“d:\\Project”), finder); —> will return 4
and
Files.walkFileTree(Paths.get(“d:\\Project”), opts, 10, finder); —> will return 6
but after testing in eclipse both will return 4, so the answer is C
Es B porque glob:*java abarca todos los archivos que terminen con la palabra “java”, y no sólo los que tengan extensión “java”
the anwser is C.
visitFile(T file, BasicFileAttributes attrs) is called when a file in the current directory is being visited