classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: java.io.File#toURI()


From: Jeroen Frijters
Subject: RE: java.io.File#toURI()
Date: Wed, 2 Jun 2004 09:47:11 +0200

Thomas Zander wrote:
> I think you want:
> 
> String path = new File(getAbsolutePath()).getConicalPath().
>       replace(separatorChar, '/');
> [...]

We definitely shouldn't do a getCanonicalPath. It may require file system 
access and it can fail in all sorts of ways. Sun doesn't canonicalize either.

> To continue the little code example:
> > if(!path.startsWith("/"))
> >   path = "/" + path;
> > return new URI(...);
> 
> If you use the getAbsolutePath() you don't need this check.

On Windows, you do. getAbsolutePath return "c:\\foo.txt" and the URL path 
should start with a slash.

Regards,
Jeroen




reply via email to

[Prev in Thread] Current Thread [Next in Thread]