Pass a local file in to URL in Java Pass a local file in to URL in Java java java

Pass a local file in to URL in Java


new File(path).toURI().toURL();


Using Java 7:

Paths.get(string).toUri().toURL();

However, you probably want to get a URI. Eg, a URI begins with file:/// but a URL with file:/ (at least, that's what toString produces).


new File("path_to_file").toURI().toURL();