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).
URI
file:///
file:/
toString
new File("path_to_file").toURI().toURL();