About Question enthuware.ocpjp.v7.2.1211 :
Moderators: Site Manager, fjwalraven
About Question enthuware.ocpjp.v7.2.1211 :
"the Path objects that we are checking contain the complete path including directories (such as c:\works\pathtest\a.java and not just a.java)" --> should *.java match against the full directory path c:\works\pathtest\a.java ?
-
- Site Admin
- Posts: 10389
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1211 :
No, that's what the explanation explains. Can you please let me know what is not clear about it?
HTH,
Paul.
HTH,
Paul.
Re: About Question enthuware.ocpjp.v7.2.1211 :
i think *.java should be matched to "c:\works\pathtest\a.java" (c:\works\pathtest\a.java = *.java). So the answer should return 1 result (instead of 0).
-
- Site Admin
- Posts: 10389
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1211 :
Please read the explanation. It explains why *.java doesn't match "c:\works\pathtest\a.java". You may also run the given code and verify.
HTH,
Paul.
HTH,
Paul.
-
- Posts: 4
- Joined: Sat Jun 01, 2013 4:42 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1211 :
BTW, if the code were like that, the result would be different... That's what the author has mentioned at the last line.
Code: Select all
void check(Path p) {
Path name = p.getFileName();
if(name != null && name.matches(p)){
count++;
}
}
-
- Posts: 53
- Joined: Fri Sep 20, 2013 7:20 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1211 :
Interesting, I just checked this and the reason you get a complete path is because the string pass to Paths.get() is an absolute path, therefore the argument to walkFileTree is an absolute Path object. If you pass a relative path to Paths.get eg "" you are passing a relative Path object to walkFileTree therefore * will match files in the working directory.
-
- Posts: 33
- Joined: Mon May 06, 2013 9:41 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1211 :
In the explanation part it should be likely p.getFileName() and not p.getFileName(p)
-
- Site Admin
- Posts: 10389
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1211 :
You are right. Fixed.
thank you for your feedback!
thank you for your feedback!
Who is online
Users browsing this forum: No registered users and 3 guests