classpath
[Top][All Lists]
Advanced

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

Re: java.io.File#toURI()


From: Thomas Zander
Subject: Re: java.io.File#toURI()
Date: Tue, 1 Jun 2004 21:34:23 +0200
User-agent: KMail/1.6.2

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Tuesday 01 June 2004 17:49, Jeroen Frijters wrote:
> This isn't going to work on Windows. I don't really know what the right
> solution is (file paths and URIs are driving me insane), but I think, at
> the very least, we need something like this:
>
> String path = abspath.replace(separatorChar, '/');
[...]
I think you want:

String path = new File(getAbsolutePath()).getConicalPath().
        replace(separatorChar, '/');
[...]

or similar :)

The point being that you want a cleaned up path as well as an absolute 
path.
so the relative paths come out correctly:
foo/bar.java -> file:///home/zander/foo/bar.java
foo/../foo/bar.java -> file:///home/zander/foo/bar.java


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.

- -- 
Thomas
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFAvNpBCojCW6H2z/QRAvj8AJ9dR7huEDthVO6WYvj2hB1K36kISQCgntX+
svtHs0AxxyII0ifpOxVy//M=
=leKT
-----END PGP SIGNATURE-----




reply via email to

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