A new feature of the Java 2 Platform is the File.toURL method, which is used to convert a pathname to a URL.
A simple example that illustrates this method is:
=============================================
import java.io.*;
import java.net.*;
public class url {
public static void main(String args[])
{
if (args.length != 1) {
System.err.println("missing filename");
System.exit(1);
}
File f = new File(args[0]);
try {
URL u = f.toURL();
System.out.println(u);
}
catch (MalformedURLException e) {
System.err.println(e);
}
}
}
For input of:
$ java url paper.txt (current directory is t:\tmp)
output is:
file:/T:/tmp/paper.txt
and this URL can be specified to view the local file in Netscape
or Microsoft web browsers. Such a method is useful in applications
that have to treat local pathnames and web-based resources in a
uniform way.
Marietta,
element k Forum Moderator