The default file system includes a logFiles directory that contains the following files:
Log-Jan 2009
log_0l_20l0
log_Feb20l0
log_Feb2011
log_10.2012
log-sum-2012
How many files Hoes the matcher in this fragment match?
PathMatcher matcher = FileSystems.getDefault ().getPathMatcher (“glob: *???_*1?” );
A.
One
B.
Two
C.
Three
D.
Four
E.
Five
F.
Six
Explanation:
The pattern to match is*???_*1?
This means at least three characters before the symbol _, folloeded by any amount of characters. The next to last character must be 1. The last character can by any character.
The following file names match this pattern:log_0l_20l0
log_Feb20l0
log_Feb2011
log_10.2012
The answer is B. cuz log_0l_20l0 and log_Feb20l0 does not have digit 1. They do have char “l”..”letter”
PathMatcher matcher = FileSystems.getDefault ().getPathMatcher (“glob:*???_*1?”);
String[] requestPath = {
“Log-Jan 2009”,
“log_0l_2010”,
“log_Feb2010”,
“log_Feb2011” ,
“log_10.2012”,
“log-sum-2012″ };
for (final String name : requestPath) {
final Path path = Paths.get(name);
System.out.print(path+ ” “);
System.out.println(matcher.matches(path));
}
The answer is D.
+1
The answer is B. cuz log_0l_20l0 and log_Feb20l0 does not have digit 1. They do have char “l”..”letter”
public static void main(String[] args){
PathMatcher matcher = FileSystems.getDefault ().getPathMatcher (“glob:*???_*1?”);
String[] requestPath = {
“Log-Jan 2009”,
“log_0l_20l0”,
“log_Feb20l0”,
“log_Feb2011” ,
“log_10.2012”,
“log-sum-2012″ };
for (final String name : requestPath) {
final Path path = Paths.get(name);
System.out.print(path+ ” “);
System.out.println(matcher.matches(path));
}
}
========================================================
Log-Jan 2009 false
log_0l_20l0 false
log_Feb20l0 false
log_Feb2011 true
log_10.2012 true
log-sum-2012 false
Correct Answer D
B
Correct answer is D. The syntax of Serg is wrong, he used l(L)in defining some of the directories instead of using 1
B true
because that is the syntax in the question, with l (L)
B
b
+1
B. The second last character must be a 1. There are three such filenames, but the last filename has no underscore, so therefore there are only 2 matches.