Construct a file: URL for a path name.
URLs in the file: scheme can be constructed for paths on
the local file system. Several possibilities need to be considered:
- If the path does not begin with a slash, then it is assumed
to reside in the users current working directory
(System.getProperty("user.dir")).
- On Windows machines, the current working directory uses
backslashes (\\, instead of /).
- If the current working directory is "/", don't add an extra
slash before the base name.
This method is declared static so that other classes
can use it directly.
/*if (pathname.startsWith("/")) {
return new URL("file://" + pathname);
}
String userdir = System.getProperty("user.dir");
userdir.replace('\\', '/');
if (userdir.endsWith("/")) {
return new URL("file:///" + userdir + pathname);
} else {
return new URL("file:///" + userdir + "/" + pathname);
}
*/
File file = new File(pathname);
return file.toURL();