Java URL Create createURL(final String address)

Here you can find the source of createURL(final String address)

Description

create URL

License

Open Source License

Declaration

public static URL createURL(final String address) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.net.MalformedURLException;
import java.net.URL;

public class Main {
    public static URL createURL(final String address) {
        try {//from  w  ww .j  a  v  a  2 s . c o m
            return new URL(address);
        } catch (final MalformedURLException e) {
            throw new RuntimeException("Can't create URL object for: "
                    + address, e);
        }
    }

    public static URL createURL(final URL url, final String query) {
        try {
            if ((url.getQuery() != null) && (!url.getQuery().isEmpty())) {
                return new URL(url.getProtocol(), url.getHost(),
                        url.getPort(), url.getFile() + "&" + query);
            }
            return new URL(url.getProtocol(), url.getHost(), url.getPort(),
                    url.getFile() + "?" + query);
        } catch (final MalformedURLException ex) {
            throw new RuntimeException(
                    "Can't create URL object for query: " + query
                            + ", URL: " + url, ex);
        }
    }
}

Related

  1. constructURLString(Map parameters)
  2. convertToURL(String host)
  3. convertToURL(String url)
  4. convertToUrl(String[] paths)
  5. convertToURLs(String[] hosts)
  6. createURL(final String protocol, final String userInfo, final String host, final int port, final String path, final String query, final String ref)
  7. createUrl(final String spec)
  8. createURL(final String url)
  9. createURL(String fileName)