Trouble understanding the meaning of the API

Alan Bateman Alan.Bateman at Sun.COM
Thu Feb 4 01:18:31 PST 2010


Marcel Ammerlaan wrote:
> Hi,
>
> I'm working with the Path API, currently implementing an HTTP 
> filesystem. I have some troubles
> understanding what the intention of the API is regarding Paths:
>
> If I create a Path like this: Path p = Paths.get("/usr/bin/xset") and 
> I do a getName() on it
> I get a Path again. 
That is correct as the method is specified to return the file name 
represented as a Path. For example, you might do 
dir.resolve(foo.getName()) to resolve the file name against another 
path. There maybe be a case for a getNameAsString or renaming getName 
but in general it's important to remember that Path != String and best 
to avoid going back and forth between Strings and Paths where possible.

> This can also be seen as p.getName().toUri() returns the full URI to 
> the original
> file, so the Path code is remembering both the full URI and the 
> name-part of it.
For the default provider, the toUri method is specified to return a URI 
with a path component that presents the absolute path. So if you invoke 
it on a simple file name or other relative path then it's the equivalent 
of toAbsolutePath().toUri().

-Alan.


More information about the nio-discuss mailing list