Path of "." and ""

Alan Bateman Alan.Bateman at oracle.com
Mon Dec 8 10:00:56 UTC 2014


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.

-Alan.


More information about the nio-dev mailing list