Java OCA OCP Practice Question 2488

Question

For which string values will the method match return true?

public static boolean match(String filename) throws Exception {
    Path path = Paths.get(filename);
    PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:/mydir/*/*");
    return (matcher.matches(path));
}
a  /mydir/notes/java/String
b  /mydir/notes/java
c  /mydir/notes
d  mydir/notes/java/String
e  mydir/notes/java


b

Note

The glob pattern /mydir// evaluates to root ( /), followed by dir mydir, followed by any two subdirectories.

Only option (b) matches this pattern.




PreviousNext

Related