Here you can find the source of buildURL(String spec)
public static URL buildURL(String spec) throws MalformedURLException
//package com.java2s; /******************************************************************************* * Copyright (c) 2007, 2008 IBM Corporation and others. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html * //www.j a va 2 s . com * Contributors: IBM Corporation - initial API and implementation *******************************************************************************/ import java.io.File; import java.net.MalformedURLException; import java.net.URL; public class Main { public static URL buildURL(String spec) throws MalformedURLException { if (spec == null) throw new NullPointerException("URL spec is null."); //$NON-NLS-1$ // Construct the URL carefully so as to preserve UNC paths etc. if (spec.startsWith("file:")) { //$NON-NLS-1$ // need to do this for UNC paths File file = new File(spec.substring(5)); if (file.isAbsolute()) return file.toURL(); } return new URL(spec); } }