Here you can find the source of fileToURL(File file)
public static URL fileToURL(File file)
//package com.java2s; /* uDig - User Friendly Desktop Internet GIS client * http://udig.refractions.net//from w w w .ja v a 2s. co m * (C) 2004-2011, Refractions Research Inc. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * (http://www.eclipse.org/legal/epl-v10.html), and the Refractions BSD * License v1.0 (http://udig.refractions.net/files/bsd3-v10.html). */ import java.io.File; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; public class Main { public static URL fileToURL(File file) { try { return file.toURI().toURL(); } catch (MalformedURLException e) { try { return file.toURI().toURL(); } catch (MalformedURLException e1) { try { return new URL("file:/" + file.getCanonicalPath().replace('\\', '/')); //$NON-NLS-1$ } catch (MalformedURLException e2) { return null; } catch (IOException e2) { return null; } } } } }