Java OCA OCP Practice Question 344

Question

Assume all the files referenced by these paths exist:

Path a = Paths.get("c:/temp/dir/a.txt");
Path b = Paths.get("c:/temp/dir/subdir/b.txt");

What is the correct string to pass to PathMatcher to match both these files?

  • A. "glob:/.txt"
  • B. "glob:.txt"
  • C. "glob:*.txt"
  • D. "glob://.txt"
  • E. "glob:/.txt"
  • F. "glob:/*.txt"
  • G. None of the above


B is correct.

Note

matches zero or more characters, including multiple directories.

A is incorrect because */ only matches one directory.

It will match "temp" but not "c:/temp," let alone "c:/temp/dir."

C is incorrect because *.txt only matches filenames and not directory paths.

D, E, and F are incorrect because the paths we want to match do not begin with a slash.

G is incorrect because of the above.




PreviousNext

Related