About Question enthuware.ocpjp.v8.2.1609 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
schchen2000
Posts: 106
Joined: Mon Mar 28, 2016 11:36 pm
Contact:

About Question enthuware.ocpjp.v8.2.1609 :

Post by schchen2000 »

p1.relativize("c:\\temp\\text2.txt");

This is wrong for two reasons -

1. relativize method does not take a String as an argument. It takes a Path object.

2. relativize method is meant to convert an absolute path into a relative path. But here, we want to convert a relative path to an absolute path. For example, p2 = p1.relativize(Paths.get("c:\\temp\\text2.txt")); will produce "..\text2.txt".
I agree that we use relativize method to generate a relative path. No disagreement here.

In the above quote, however, you said something confusing:

"But here, we want to convert a relative path to an absolute path."

Did you mean to say the following?

To tackle the problem in the question, we need to generate an absolute path as a result. We need to consume a relative path and use it with the given absolute path (p1) to generate such an absolute path.

Is that what you mean to say when you said "But here, we want to convert a relative path to an absolute path.".

Thanks.

Schmichael

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

Re: About Question enthuware.ocpjp.v8.2.1609 :

Post by admin »

schchen2000 wrote: In the above quote, however, you said something confusing:

"But here, we want to convert a relative path to an absolute path."

Did you mean to say the following?

To tackle the problem in the question, we need to generate an absolute path as a result. We need to consume a relative path and use it with the given absolute path (p1) to generate such an absolute path.

Is that what you mean to say when you said "But here, we want to convert a relative path to an absolute path.".

Thanks.

Schmichael
Yes, we already have a relative path to text2.txt i.e. .\text2.txt since it is in the same directory as test1.txt. But we want its absolute path so that we can open it.

HTH,
Paul.

schchen2000
Posts: 106
Joined: Mon Mar 28, 2016 11:36 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1609 :

Post by schchen2000 »

Thanks a lot, Paul.

jme_chg
Posts: 29
Joined: Sun Feb 07, 2021 6:30 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1609 :

Post by jme_chg »

I'm confused with the explanation for B.

It says we want the absolute path... why does it need to be absolute?

Surely it depends on where the current directory? e.g. if we're already in c:\, then new FileWriter("temp/text2.txt") will open ok.
Or do we want absolute because we assume we have no idea where the current directory is?

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

Re: About Question enthuware.ocpjp.v8.2.1609 :

Post by admin »

Right, the problem statement gives no indication of the current directory.

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests