Basic usage question

Alan Bateman Alan.Bateman at oracle.com
Thu Jul 29 12:22:28 PDT 2010


Kasper Nielsen wrote:
> Hi,
>
> I've been unable to answer this _very_ basic question.
>
> Considering the following code using the regular File class.
>
> File f = new File("/home/foo");
> File fnew = new File(f, "tmp");
>
> How do I do this done using the Path class?
>
> Do I need to resort to using something like this?
>
> Path p=Paths.get("/home/foo");
> Path ptmp=Paths.get(p.toString() + p.getFileSystem().getSeparator()  +
> "tmp")?
>
> Cheers
>  Kasper
Are you looking for the resolve methods? For the above then 
Paths.get("/home/foo").resolve("tmp") will do it. The resolve methods 
are actually more functional than the 2-arg File constructor in that 
they know how to resolve all combinations of paths (important on 
platforms like Windows where there are at least 5 types of paths).

-Alan.


More information about the nio-discuss mailing list