Here you can find the source of createURL(String url, String baseURI)
Parameter | Description |
---|---|
url | a URL string. |
baseURI | a base url string to assist in creating a URL. |
Parameter | Description |
---|---|
MalformedURLException | if a malformed URL has occurred. |
public static URL createURL(String url, String baseURI) throws MalformedURLException
//package com.java2s; /******************************************************************************* * Copyright (c) 2002-2005 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 * * Contributors:/* w w w . ja v a2 s . c o m*/ * IBM - Initial API and implementation *******************************************************************************/ import java.net.MalformedURLException; import java.net.URI; import java.net.URL; public class Main { /** * Create URL using base URI. * * @param url a URL string. * @param baseURI a base url string to assist in creating a URL. * @return newly created URL. * @throws MalformedURLException if a malformed URL has occurred. */ public static URL createURL(String url, String baseURI) throws MalformedURLException { URL returnURL = null; URI uri = null; try { returnURL = new URL(url); uri = new URI(url); uri = uri.normalize(); returnURL = new URL(uri.toString()); } catch (Exception mue) { int i = baseURI.lastIndexOf('/'); int j = baseURI.lastIndexOf('\\'); if (j > i) i = j; try { uri = new URI(baseURI.substring(0, i + 1) + url); uri = uri.normalize(); returnURL = uri.toURL(); } catch (Exception e) { return new URL(baseURI.substring(0, i + 1) + url); } } return returnURL; } }