Page 1 of 1

About Question enthuware.ocpjp.v8.2.1609 :

Posted: Sun May 15, 2016 2:58 pm
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

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

Posted: Sun May 15, 2016 8:47 pm
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.

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

Posted: Sun May 15, 2016 10:10 pm
by schchen2000
Thanks a lot, Paul.

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

Posted: Mon Mar 22, 2021 1:54 pm
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?

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

Posted: Mon Mar 22, 2021 8:39 pm
by admin
Right, the problem statement gives no indication of the current directory.