List of utility methods to do File to URL
URL | fileToURL(File f) This method is added because the default conversion using file.toURL() turns out to be rather slow, as it tries to figure out if the file is actually a directory.
String absPath = f.getAbsolutePath(); char sep = File.separatorChar; if (sep != '/') { absPath = absPath.replace(sep, '/'); if (absPath.length() > 0 && absPath.charAt(0) != '/') { ... |
URL | fileToURL(File file) file To URL return new URL("file", "", filenameToURI(file.getCanonicalPath())); |
URL | fileToURL(File file) Returns a URL corresponding to the specified File or null if the File cannot be converted into a URL .
try { String path = file.getAbsolutePath(); if (File.separatorChar != '/') path = path.replace(File.separatorChar, '/'); if (!path.startsWith("/")) path = "/" + path; if (!path.endsWith("/") && file.isDirectory()) path = path + "/"; ... |
URL | fileToUrl(File file) file To Url return new URL("file:///" + file.getCanonicalPath().replaceAll("\\\\", "/")); |
URL | FileToURL(File file) File To URL return file.toURI().toURL();
|
URL | fileToURL(File file) Converts a File to a file: URL. try { file = file.getCanonicalFile(); } catch (IOException ignored) { file = file.getAbsoluteFile(); URL url; try { String path = file.getPath().replace('\\', '/'); ... |
URL | fileToURL(File file) file To URL file = file.getCanonicalFile(); String s = file.getAbsolutePath(); s = s.replace('\\', '/'); if (!s.startsWith("/")) s = "/" + s; if (!s.endsWith("/") && file.isDirectory()) s = s + "/"; return new URL("file", "", s); ... |
URL | fileToURL(File file) A replacement for File.toURI().toURL(). try { URL url = file.toURI().toURL(); String string = url.toExternalForm(); if (string.contains("+")) { string = string.replace("+", "%2B"); if (string.contains(" ")) { string = string.replace(" ", "%20"); ... |
URL | fileToURL(File file) file To URL try { return file.toURI().toURL(); } catch (MalformedURLException e) { try { return file.toURI().toURL(); } catch (MalformedURLException e1) { try { return new URL("file:/" + file.getCanonicalPath().replace('\\', '/')); ... |
URL | fileToURL(File file) file To URL try { return file.toURI().toURL(); } catch (MalformedURLException e) { throw new RuntimeException("Unexpected exception on file [" + file + "]", e); |