Page 1 of 1
About Question enthuware.ocpjp.v7.2.1211 :
Posted: Thu Feb 21, 2013 4:56 pm
by ETS User
"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 ?
Re: About Question enthuware.ocpjp.v7.2.1211 :
Posted: Thu Feb 21, 2013 6:59 pm
by admin
No, that's what the explanation explains. Can you please let me know what is not clear about it?
HTH,
Paul.
Re: About Question enthuware.ocpjp.v7.2.1211 :
Posted: Thu Feb 21, 2013 8:15 pm
by Guest
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).
Re: About Question enthuware.ocpjp.v7.2.1211 :
Posted: Thu Feb 21, 2013 8:33 pm
by admin
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.
Re: About Question enthuware.ocpjp.v7.2.1211 :
Posted: Sun Jun 02, 2013 8:04 am
by makopo
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++;
}
}
Re: About Question enthuware.ocpjp.v7.2.1211 :
Posted: Tue Oct 08, 2013 10:56 am
by Student
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.
Re: About Question enthuware.ocpjp.v7.2.1211 :
Posted: Mon Aug 04, 2014 8:42 am
by bptoth
In the explanation part it should be likely p.getFileName() and not p.getFileName(p)
Re: About Question enthuware.ocpjp.v7.2.1211 :
Posted: Mon Aug 04, 2014 8:27 pm
by admin
You are right. Fixed.
thank you for your feedback!