Java tutorial
//package com.java2s; import java.io.File; import java.net.MalformedURLException; import java.net.URL; public class Main { public static URL createURL(String fileName) throws MalformedURLException { URL url = null; try { url = new URL(fileName); } catch (MalformedURLException ex) { File f = new File(fileName); try { String path = f.getAbsolutePath(); String fs = System.getProperty("file.separator"); if (fs.length() == 1) { char sep = fs.charAt(0); if (sep != '/') { path = path.replace(sep, '/'); } if (path.charAt(0) != '/') { path = '/' + path; } } path = "file://" + path; url = new URL(path); } catch (MalformedURLException e) { throw e; } } return url; } }