Java Utililty Methods URL Create

List of utility methods to do URL Create

Description

The list of methods to do URL Create are organized into topic(s).

Method

URLcreateUrl(final String spec)
Creates a new URL from the specified URL spec.
return createUrl(null, spec);
URLcreateURL(final String url)
create URL
try {
    return new URL(url);
} catch (MalformedURLException e) {
    throw new RuntimeException(e);
URLcreateURL(String fileName)
create URL
try {
    return new URL(fileName);
} catch (MalformedURLException ex) {
    File file = new File(fileName);
    String path = file.getAbsolutePath();
    String fs = System.getProperty("file.separator");
    if (fs.length() == 1) {
        char sep = fs.charAt(0);
...
java.net.URLcreateUrl(String spec)
create Url
try {
    return new java.net.URL(spec);
} catch (java.net.MalformedURLException murle) {
    throw new RuntimeException(spec, murle);
URLcreateURL(String spec, URLStreamHandlerFactory urlHandlerFactory)
Tries to parse a String as an URL.
URLStreamHandler handler = getURLHandler(spec, urlHandlerFactory);
URL url;
try {
    if (handler == null) {
        url = new URL(spec);
    } else {
        url = new URL(null, spec, handler);
} catch (MalformedURLException e) {
    url = null;
return url;
URLcreateURL(String src, File basedir)
Converts a string to a URL.
URL srcURL;
try {
    srcURL = new URL(src);
} catch (MalformedURLException e) {
    File srcFile = new File(src);
    if (!srcFile.isAbsolute()) {
        srcFile = new File(basedir, src);
    srcURL = srcFile.toURI().toURL();
return srcURL;
StringcreateURL(String str)
create URL
try {
    new URL(str);
    return null;
} catch (MalformedURLException var2) {
    return "http://" + str;
URLcreateURL(String url)
Create a URL, and throw a RuntimeException upon failure.
try {
    return new URL(url);
} catch (MalformedURLException e) {
    throw new RuntimeException(e);
URLcreateURL(String url)
create URL
URL requestURL;
try {
    requestURL = new URL(url);
    return requestURL;
} catch (MalformedURLException e) {
    try {
        requestURL = new URL("http://localhost:8080" + url);
        return requestURL;
...
URLcreateURL(String url)
converts a string into an url via the utf-8 encoder
try {
    return new URL(url);
} catch (Exception e) {
    return null;