Page 1 of 1

About Question enthuware.ocpjp.v7.2.1603 :

Posted: Mon Mar 21, 2016 5:07 pm
by doziransky
Hi,

I understand everything about this question except one thing.

Where does "file:///" come from?

When I looked at the toUri() method in the java api it said:

"This method constructs an absolute URI with a scheme equal to the URI scheme that identifies the provider. The exact form of the scheme specific part is highly provider dependent."

So isn't it possible this won't start with "file:///"?

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

Posted: Mon Mar 21, 2016 9:21 pm
by admin
It is certainly possible that it won't start with file:///. But no other options are given so it is ok to assume that on this particular system it will start with file:/// (if there is no exception, of course).

HTH,
Paul.

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

Posted: Sat Jun 10, 2017 2:49 pm
by Cannelids
Re the quote from the API “... an empty path is returned if this path does have a root component and all name elements are redundant" I tried this and do see the root e.g.
Path p1 = Paths.get("c:/x/../y/../z/..");
System.out.println(p1.normalize());
prints "c:" not "" (nothing).
Do you think this might be a typo in the API? Maybe it should read "... does not have a root component ...”?

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

Posted: Sat Jun 10, 2017 11:00 pm
by admin
Can you please post the link where you saw this written?

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

Posted: Sun Jun 11, 2017 4:41 pm
by Cannelids
The "Returns" section of the full method description in https://docs.oracle.com/javase/7/docs/a ... /Path.html
Same in the descriptive comment in the source code file as seen via NetBeans (Navigate > Go to Source)
(And then reproduced in the Explanation for this Enthuware Q)

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

Posted: Sun Jun 11, 2017 9:50 pm
by admin
I see. Yes, it could be a typo.

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

Posted: Mon Jun 12, 2017 1:50 pm
by Cannelids
Thanks - good to have an opinion from a much more knowledgable source :ugeek:

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

Posted: Sat Jan 11, 2025 12:48 pm
by user_m1k0
for my env output is:

```

Code: Select all

Defined import java.nio.file.Path
Defined import java.nio.file.Paths

Defined field Path p1 = c:\..\temp\test.txt

System.out.println(p1.normalize().toUri())
file:///usr/lib/jvm/java-21-openjdk-21.0.5.0.11-1.fc41.x86_64/bin/c:%5C..%5Ctemp%5Ctest.txt
```