Save
Busy. Please wait.
Log in with Clever
or

show password
Forgot Password?

Don't have an account?  Sign up 
Sign up using Clever
or

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.
Your email address is only used to allow you to reset your password. See 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.
focusNode
Didn't know it?
click below
 
Knew it?
click below
Don't Know
Remaining cards (0)
Know
0:00
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

OCPJP708.5

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
Popular Computers sets

 

 



Voices

Use these flashcards to help memorize information. Look at the large card and try to recall what is on the other side. Then click the card to flip it. If you knew the answer, click the green Know box. Otherwise, click the red Don't know box.

When you've placed seven or more cards in the Don't know box, click "retry" to try those cards again.

If you've accidentally put the card in the wrong box, just click on the card to take it out of the box.

You can also use your keyboard to move the cards as follows:

If you are logged in to your account, this website will remember which cards you know and don't know so that they are in the same box the next time you log in.

When you need a break, try one of the other activities listed below the flashcards like Matching, Snowman, or Hungry Bug. Although it may feel like you're playing a game, your brain is still making more connections with the information to help you out.

To see how well you know the information, try the Quiz or Test activity.

Pass complete!
"Know" box contains:
Time elapsed:
Retries:
restart all cards