The default file system includes a logFiles directory that contains the following files:
log – Jan2009
log_01_2010
log_Feb2010
log_Feb2011
log-sum-2012
How many files 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 glob pattern is: any three characters, followed by _ ,followed by any number of
characters, and ending with a 1.
Only log_Feb2011 matches this pattern.
Note:
You can use glob syntax to specify pattern-matching behavior.
A glob pattern is specified as a string and is matched against other strings, such as directory or file
names. Glob syntax follows several simple rules:
* An asterisk, *, matches any number of characters (including none).
** Two asterisks, **, works like * but crosses directory boundaries. This syntax is generally used
for matching complete paths.
* A question mark, ?, matches exactly one character.
* Braces specify a collection of subpatterns. For example:
{sun,moon,stars} matches “sun”, “moon”, or “stars.”
{temp*,tmp*} matches all strings beginning with “temp” or “tmp.”
* Square brackets convey a set of single characters or, when the hyphen character (-) is used, a
range of characters. For example:
[aeiou] matches any lowercase vowel.
[0-9] matches any digit.
[A-Z] matches any uppercase letter.
[a-z,A-Z] matches any uppercase or lowercase letter.
* Within the square brackets, *, ?, and \ match themselves.
*All other characters match themselves.
* To match *, ?, or the other special characters, you can escape them by using the backslash
character, \. For example: \\ matches a single backslash, and \? matches the question mark.
Reference: The Java Tutorials
Finding Files
What Is a Glob?