Path of "." and ""

Wang Weijun weijun.wang at oracle.com
Mon Dec 8 10:37:51 UTC 2014


> On Dec 8, 2014, at 18:00, Alan Bateman <Alan.Bateman at oracle.com> wrote:
> 
> On 08/12/2014 09:37, Wang Weijun wrote:
>> Path p1 = Paths.get(".");
>> Path p2 = Paths.get("./s");
>> 
>> Then p2.startsWith(p1) is true.
>> 
>> If I normalize them, p1 becomes "", p2 becomes "s", and p2.startsWith(p1) is false.
>> 
>> I know it's because after normalizing, p1 has an element which is "", and p2 has an element which is "s", therefore one array does not starts with the other. Maybe p1 should be normalized to no element at all?
>> 
>> And what is the best way to check if one path is inside another? I do not want to call toAbsolutePath().
>> 
> If you iterate from 0 to name count and call subpath then you it will give you the set of tails. Use that with p2.startWith(p1) then I think it should do what you want.

Can you be more detailed? For the 2 paths above (after normalized) there is only subpath(0,1) that computes and the result is the same as the full path.

I also noticed that even if the startsWith method returns false, the p1.relativize(p2) returns a simple "s".

Also, the p1.relativize(p1) is empty but its getNameCount() is 1.

Why is there no isEmpty()?

I'll need to write a bunch of helper methods.

--Max


> 
> -Alan.



More information about the nio-dev mailing list