@Test public void testFileToUrl() { String url = URLs.fileToUrl(new File("file café")).toString(); assertTrue("Expected '" + url + "' to start with 'file:'", url.startsWith("file:")); assertTrue( "Expected '" + url + "' to end with 'file%20caf%C3%A9'", url.endsWith("file%20caf%C3%A9")); }
public static URL fileToUrl(File file) { try { String string = file.toURI().toASCIIString(); if (string.contains("+")) { string = string.replace("+", "%2B"); } if (string.contains(" ")) { string = string.replace(" ", "%20"); } return new URL(string); } catch (MalformedURLException e) { return null; } }
URLs { public static URL fileToUrl(File file) { try { String string = file.toURI().toASCIIString(); if (string.contains("+")) { string = string.replace("+", "%2B"); } if (string.contains(" ")) { string = string.replace(" ", "%20"); } return new URL(string); } catch (MalformedURLException e) { return null; } } }
URLs { public static URL fileToUrl(File file) { try { String string = file.toURI().toASCIIString(); if (string.contains("+")) { string = string.replace("+", "%2B"); } if (string.contains(" ")) { string = string.replace(" ", "%20"); } return new URL(string); } catch (MalformedURLException e) { return null; } }  }
URLs { public static URL fileToUrl(File file) { try { String string = file.toURI().toASCIIString(); if (string.contains("+")) { string = string.replace("+", "%2B"); } if (string.contains(" ")) { string = string.replace(" ", "%20"); } return new URL(string); } catch (MalformedURLException e) { return null; } }  static URL changeUrlExt(URL url, String postfix); static URL extendUrl(URL base, String extension); static URL fileToUrl(File file); static URL getParentUrl(URL url); static File urlToFile(URL url); }
URLs { public static URL fileToUrl(File file) { try { String string = file.toURI().toASCIIString(); if (string.contains("+")) { string = string.replace("+", "%2B"); } if (string.contains(" ")) { string = string.replace(" ", "%20"); } return new URL(string); } catch (MalformedURLException e) { return null; } }  static URL changeUrlExt(URL url, String postfix); static URL extendUrl(URL base, String extension); static URL fileToUrl(File file); static URL getParentUrl(URL url); static File urlToFile(URL url);  }