Pasquale Bonito

Greenhorn
+ Follow
since Aug 05, 2015
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
2
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Pasquale Bonito

I tried it as well, and I didn't catch any exception since directory c:\x exists and path is normalized deleting ../y before looking at the real path.

I agree thta if the path does not exists on filesystem you hava an exceptio.
8 years ago
The question is not about if that methods throws Exception or not but if it throws Exception in a specific case.

What happens if you create a dir "x" with no child under c:\ and than run a program with this line of code ? System.out.println(Paths.get("c:/x/z/..").toRealPath());
8 years ago
I looked at javadoc as well and it's clear thatt .. removes previous dir. It seems that the exercise in Sierra/Bates is wrong.

thanks
8 years ago
Hi all,
I saw this test in Sierra/Bates study guide:

Having a directory x under c: drive what is the result of System.out.println(Paths.get("c:/x/z/..").toRealPath()); ?

I answered c:\x but according to the solution this is wrong. Correct solution should be: throws NoSuchFileException. The toRealPath() function actually looks at the filesystem. Since there is no directory named z an exception is thrown.

I thought that path was normalized removing directory z, but according the solution this should not be done.

However If i try
System.out.println(Paths.get("c:/users/BONPAS00/Documents/XXXXX/..").toRealPath());

the output is C:\Users\BONPAS00\Documents.

So I don't underdsand the exact behavior.

Thanks
8 years ago