About Question enthuware.ocpjp.v7.2.1211 :

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
ETS User

About Question enthuware.ocpjp.v7.2.1211 :

Post 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 ?

admin
Site Admin
Posts: 10389
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1211 :

Post by admin »

No, that's what the explanation explains. Can you please let me know what is not clear about it?

HTH,
Paul.

Guest

Re: About Question enthuware.ocpjp.v7.2.1211 :

Post 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).

admin
Site Admin
Posts: 10389
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1211 :

Post 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.

makopo
Posts: 4
Joined: Sat Jun 01, 2013 4:42 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1211 :

Post 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++;     
         }
}

Student
Posts: 53
Joined: Fri Sep 20, 2013 7:20 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1211 :

Post 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.

bptoth
Posts: 33
Joined: Mon May 06, 2013 9:41 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1211 :

Post by bptoth »

In the explanation part it should be likely p.getFileName() and not p.getFileName(p)

admin
Site Admin
Posts: 10389
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1211 :

Post by admin »

You are right. Fixed.
thank you for your feedback!

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests