Busy. Please wait.

show password
Forgot Password?

Don't have an account?  Sign up 

Username is available taken
show password


Make sure to remember your password. If you forget it there is no way for StudyStack to send you a reset link. You would need to create a new account.
We do not share your email address with others. It is only used to allow you to reset your password. For details read our Privacy Policy and Terms of Service.

Already a StudyStack user? Log In

Reset Password
Enter the associated with your account, and we'll email you a link to reset your password.

Remove ads
Don't know
remaining cards
To flip the current card, click it or press the Spacebar key.  To move the current card to one of the three colored boxes, click on the box.  You may also press the UP ARROW key to move the card to the "Know" box, the DOWN ARROW key to move the card to the "Don't know" box, or the RIGHT ARROW key to move the card to the Remaining box.  You may also click on the card displayed in any of the three boxes to bring that card back to the center.

Pass complete!

"Know" box contains:
Time elapsed:
restart all cards

Embed Code - If you would like this activity on your web page, copy the script below and paste it into your web page.

  Normal Size     Small Size show me how


Cert Obj Find a file with PathMatcher interface.

[8.5.1] Objective Find a file with PathMatcher interface.
[8.5.2] What is a glob? PathMatchers use a new type that you probably haven't seen before called a glob. Globs are not regular expressions, although they might look similar at first.
[8.5.3]In the world of globs, one asterisk means "match any character except for a directory boundary." Two asterisks means "match any character, including a directory boundary." Path path = Paths.get("/com/java/One.java"); matches(path, "glob:*.java"); // false matches(path, "glob:**/*.java"); // true matches(path, "glob:*"); // false matches(path, "glob:**"); // true
[8.5.4] Remember that we are using a file system–specific PathMatcher. This means slashes and backslashes can be treated differently, depending on what operating system you happen to be running. The previous example does print the same output on both Windows and UNIX because it uses forward slashes.
[8.5.5] Unix vs Windows Path path = Paths.get("com\\java\\One.java"); Now Windows still prints: false true false true However, UNIX prints: true false true true
[8.5.6] Preferred Why? Because UNIX doesn't see the backslash as a directory boundary. The lesson here is to use / instead of \\ so your code behaves more predictably across operating systems.
[8.5.7]A question mark matches any character. A character could be a letter or a number or anything else Path path1 = Paths.get("One.java"); Path path2 = Paths.get("One.ja^a"); matches(path1, "glob:*.????"); // true matches(path1, "glob:*.???"); // false matches(path2, "glob:*.????"); // true matches(path2, "glob:*.???"); // false
[8.5.8]Boilerplate code public void matches(Path path, String glob) { PathMatcher matcher = FileSystems.getDefault().getPathMatcher(glob); System.out.println(matcher.matches(path)); }
[8.5.9] More examples Path path1 = Paths.get("Bert-book"); Path path2 = Paths.get("Kathy-horse"); matches(path1, "glob:{Bert*,Kathy*}"); // true matches(path2, "glob:{Bert,Kathy}*"); // true matches(path1, "glob:{Bert,Kathy}"); // false
[8.5.10] More on glob1 (Java won't let you type a single backslash, so you have to escape the backslash itself with another backslash.) ■ [0-9] One single digit. Can also be read as any one character from 0 to 9. ■ \\* The literal character asterisk rather than the asterisk that means to match anything. A single backslash before * escapes it.
[8.5.11] More on glob2 ■ {A*,b} Either a capital A followed by anything or the single character b. ■ /**/ One or more directories with any name. ■ 1 The single character 1.
Created by: MVK2013