Here you can find the source of getUrlFromPath(String path)
public static URL getUrlFromPath(String path) throws MalformedURLException
//package com.java2s; //License from project: Apache License import java.io.File; import java.net.MalformedURLException; import java.net.URL; public class Main { public static URL getUrlFromPath(String path) throws MalformedURLException { if (isLocalPath(path)) { return new File(path).toURI().toURL(); } else {//from w ww . j a va 2s .c o m return new URL(path); } } public static boolean isLocalPath(String path) { try { new URL(path); return false; } catch (MalformedURLException e) { return true; } } }