diff options
author | Anthony Green <green@redhat.com> | 2004-07-06 02:52:54 +0000 |
---|---|---|
committer | Anthony Green <green@gcc.gnu.org> | 2004-07-06 02:52:54 +0000 |
commit | 23f99379d3d3d445c15f7a3c2e29e44c06afb255 (patch) | |
tree | bc155c692b8d7595ad016211c488bbc3005e29f2 /libjava/java | |
parent | 5377d5ba398d4949af937fc025c1b01203aa3315 (diff) | |
download | gcc-23f99379d3d3d445c15f7a3c2e29e44c06afb255.zip gcc-23f99379d3d3d445c15f7a3c2e29e44c06afb255.tar.gz gcc-23f99379d3d3d445c15f7a3c2e29e44c06afb255.tar.bz2 |
File.java (toURI): Merge from Classpath.
2004-07-05 Anthony Green <green@redhat.com>
* java/io/File.java (toURI): Merge from Classpath.
From-SVN: r84145
Diffstat (limited to 'libjava/java')
-rw-r--r-- | libjava/java/io/File.java | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/libjava/java/io/File.java b/libjava/java/io/File.java index 53ae529..47f18b5 100644 --- a/libjava/java/io/File.java +++ b/libjava/java/io/File.java @@ -40,6 +40,8 @@ exception statement from your version. */ package java.io; import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import gnu.classpath.Configuration; import gnu.gcj.runtime.FileDeleter; @@ -875,6 +877,28 @@ public class File implements Serializable, Comparable } /** + * @return A <code>URI</code> for this object. + */ + public URI toURI() + { + String abspath = getAbsolutePath(); + + if (isDirectory()) + abspath = abspath + separator; + + try + { + return new URI("file", "", abspath.replace(separatorChar, '/')); + } + catch (URISyntaxException use) + { + // Can't happen. + throw (InternalError) new InternalError("Unconvertible file: " + + this).initCause(use); + } + } + + /** * This method returns a <code>URL</code> with the <code>file:</code> * protocol that represents this file. The exact form of this URL is * system dependent. |