Here you can find the source of fileToURL(String filename)
public static URL fileToURL(String filename)
//package com.java2s; //License from project: BSD License import java.io.File; import java.net.MalformedURLException; import java.net.URL; public class Main { public static URL fileToURL(String filename) { try {//from w w w . j a v a 2s . co m return new File(filename).toURI().toURL(); } catch (MalformedURLException e) { e.printStackTrace(); return null; } } }