Here you can find the source of createURL(final String url)
public static URL createURL(final String url)
//package com.java2s; /*//from w w w.ja v a 2s. c o m * Copyright 2005-2010 the original author or authors. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.net.MalformedURLException; import java.net.URL; public class Main { private static final String SLASH = "/"; private static final String FILE_PROTOCOL = "file"; public static URL createURL(final String url) { try { return new URL(url); } catch (MalformedURLException e) { throw new RuntimeException(e); } } public static URL createURL(final URL baseURL, String relativeURL) { try { String protocol = baseURL.getProtocol(); relativeURL = relativeURL.replace("\\", SLASH); // TODO if (protocol.startsWith(FILE_PROTOCOL)) { if (relativeURL.startsWith(SLASH)) { relativeURL = relativeURL.substring(1, relativeURL.length()); } return new URL(baseURL, relativeURL); } else { // TODO String baseArchivePath = baseURL.toExternalForm(); if (baseArchivePath.endsWith(SLASH)) { baseArchivePath = baseArchivePath.substring(0, baseArchivePath.length() - 1); } if (baseArchivePath.endsWith("!")) { baseArchivePath = baseArchivePath.substring(0, baseArchivePath.length() - 1); } if (!relativeURL.startsWith(SLASH)) { relativeURL = SLASH + relativeURL; } return new URL(baseArchivePath + "!" + relativeURL); } } catch (MalformedURLException e) { throw new RuntimeException(e); } } }