Why does the new File(URI) constructor restricts the uri to hierarchical?

Michael McMahon michael.x.mcmahon at oracle.com
Mon May 16 03:00:48 PDT 2011


Paulo,

URI's with a scheme (such as file:) cannot be relative. That's a feature of
the specification of URIs themselves. So, this behavior is a side-effect 
of the
requirement that the URI provided to the constructor has a file: scheme.

- Michael.

On 14/05/11 18:24, Paulo Levi wrote:
> I have a mapping from uri to real files, and to i was hoping to use 
> that constructor to do the work, however it says it only accepts,
>
> "absolute, hierarchical URI with a scheme equal to "file""
>
> Now, many times on html files the uri would be the second notion of 
> hierarchical from the javadoc
>
> "A /hierarchical/ URI is either an absolute URI whose scheme-specific 
> part begins with a slash character, *or a relative URI, that is, a URI 
> that does not specify a scheme.*"
>
> As in a relative file for instance. But the constructor will never 
> accept this since they obviously have no schema. I was hoping to fake 
> it by introducing the file schema on uris that don't have it and 
> joining the current file parent directory to make a relative uri absolute.
>
> But why doesn't the constructor allow this?
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/net-dev/attachments/20110516/60e724e2/attachment.html 


More information about the net-dev mailing list