Page 1 of 1

About Question enthuware.ocpjp.v7.2.1599 :

Posted: Sun Sep 07, 2014 1:08 pm
by hamada.yamasaki
How come
Paths.get("\\index.html");
has root. The root under linux is / and for windows is c:\

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

Posted: Sun Sep 07, 2014 8:41 pm
by admin
It considers a path starting with \\ as root as well. Although they haven't specified an exact definition of a root anywhere.

You may want to try it out.
-Paul.

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

Posted: Sat Jun 20, 2015 11:45 am
by razvan.luca
I'm don't understand why Explanation is saying that "if a path starts with a // or c:" has a root, but example is with "\\"
Paths.get("\\index.html");

It doesn't matter if it's starting with "\\" or "//", that's always a root?

Thanks

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

Posted: Sat Jun 20, 2015 9:24 pm
by admin
Well, On *nix systems, path separator is /, a path starting with \ is not root.

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

Posted: Sun Nov 15, 2015 12:23 pm
by Jimothy
Prints the following on my linux box:
../\index.html

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

Posted: Tue Apr 19, 2016 1:02 pm
by zhengye1
To run the code in linux, you need to create the path object like this

Code: Select all

        Path p1 = Paths.get("photos/goa"); 
        Path p2 = Paths.get("/index.html"); 
because the root in Linux is "/"...

I want to know in the real exam, do they specified which OS they using? If not , it seems like ambiguous about the separator...

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

Posted: Tue Apr 19, 2016 8:02 pm
by admin
In the exam, you can assume that if the separater is /, then the code is for linux and if it is \\, then the code is for windows.

HTH,
Paul.

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

Posted: Mon Jan 02, 2017 1:17 am
by jagoneye
So on nix systems I am assuming "/" has to escaped to "//" hence the code in question also causes error? Am I right?

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

Posted: Mon Jan 02, 2017 12:17 pm
by admin
No, on a *nix based system, you do not need to escape /.