List of utility methods to do File to URL
URL | fileToURL(File file) file To URL String path = file.getAbsolutePath(); path = URLEncoder.encode(path, "UTF8"); if (!path.startsWith("/")) { path = "/" + path; if (!path.endsWith("/") && file.isDirectory()) { path = path + "/"; URL url = new URL("file", "", path); return url; |
URL[] | fileToURL(File... files) file To URL URL[] urls = new URL[files.length]; int i = 0; for (File file : files) { urls[i] = file.toURI().toURL(); i++; return urls; |
URL | fileToURL(String file) file To URL File f = new File(file); return f.toURI().toURL(); |
String | fileToURL(String filename) file To URL File f = new File(filename); try { return f.toURI().toURL().toString(); } catch (MalformedURLException e) { return filename; |
URL | fileToURL(String filename) file To URL try { return new File(filename).toURI().toURL(); } catch (MalformedURLException e) { e.printStackTrace(); return null; |
String | fileToURLString(File file) file To URL String return file.toURI().toURL().toString();
|