Here you can find the source of createURL(String fileName)
public static URL createURL(String fileName) throws Exception
//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 Exception { try {//www . ja va 2 s .c o m return new URL(fileName); } catch (MalformedURLException ex) { File file = new File(fileName); String path = file.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; return new URL(path); } } }