summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authorMark Wielaard <mark@klomp.org>2004-04-30 20:21:31 +0000
committerMark Wielaard <mark@klomp.org>2004-04-30 20:21:31 +0000
commit6189c0c0fefda9766401916198740bca276e9b34 (patch)
tree2b3cfe0c6eed645c79ca624f257467d27c51120d /java
parent94dc054487b47044ad77dd6e0cb517fb6d12b940 (diff)
downloadclasspath-6189c0c0fefda9766401916198740bca276e9b34.tar.gz
2004-04-30 Tom Tromey <tromey@redhat.com>
Mark Wielaard <mark@klomp.org> * java/io/File.java (toURI): New method. (toURL): Use isDirectory() directly.
Diffstat (limited to 'java')
-rw-r--r--java/io/File.java36
1 files changed, 28 insertions, 8 deletions
diff --git a/java/io/File.java b/java/io/File.java
index 0843f8747..b3319e336 100644
--- a/java/io/File.java
+++ b/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.java.io.PlatformHelper;
@@ -766,6 +768,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.
@@ -778,14 +802,10 @@ public class File implements Serializable, Comparable
public URL toURL() throws MalformedURLException
{
String abspath = getAbsolutePath();
-
- try
- {
- if (new File(abspath).isDirectory())
- abspath = abspath + separator;
- }
- catch(Exception _) { }
-
+
+ if (isDirectory())
+ abspath = abspath + separator;
+
return new URL("file", "", abspath.replace(separatorChar, '/'));
}