Java URL Resolve resolve(final URL url)

Here you can find the source of resolve(final URL url)

Description

resolve

License

Open Source License

Parameter

Parameter Description
url The URL to resolve (can be workspace-relative)

Return

The file corresponding to the given URL

Declaration

public static File resolve(final URL url) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2009, 2015 Fabian Steeg. 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
 * <p/>//from  w w  w .  ja va  2  s  .  com
 * Contributors: Fabian Steeg - initial API and implementation; see bug 277380
 *******************************************************************************/

import java.io.File;

import java.net.URISyntaxException;
import java.net.URL;

public class Main {
    /**
     * @param url
     *            The URL to resolve (can be workspace-relative)
     * @return The file corresponding to the given URL
     */
    public static File resolve(final URL url) {
        File resultFile = null;
        URL resolved = url;
        /*
         * If we don't check the protocol here, the FileLocator throws a
         * NullPointerException if the URL is a normal file URL.
         */
        if (!url.getProtocol().equals("file")) { //$NON-NLS-1$
            throw new IllegalArgumentException("Unsupported protocol: " //$NON-NLS-1$
                    + url.getProtocol());
        }
        try {
            resultFile = new File(resolved.toURI());
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
        return resultFile;
    }
}

Related

  1. resolve(URL base, String relUrl)
  2. resolve(URL base, String uri)
  3. resolveGoogleRedirect(String url)
  4. resolveHref(String baseUrl, String href)