Java URL Value Check isUrl(String resourceLocation)

Here you can find the source of isUrl(String resourceLocation)

Description

Return whether the given resource location is a URL: either a special "classpath" pseudo URL or a standard URL.

License

Open Source License

Declaration

public static boolean isUrl(String resourceLocation) 

Method Source Code

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

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

public class Main {
    /** Pseudo URL prefix for loading from the class path: "classpath:" */
    public static final String CLASSPATH_URL_PREFIX = "classpath:";

    /**/*from  w  ww .  j av  a2s  . co  m*/
     * Return whether the given resource location is a URL: either a special
     * "classpath" pseudo URL or a standard URL.
     * 
     * @see #CLASSPATH_URL_PREFIX
     * @see java.net.URL
     */
    public static boolean isUrl(String resourceLocation) {
        if (resourceLocation.startsWith(CLASSPATH_URL_PREFIX)) {
            return true;
        }
        try {
            new URL(resourceLocation);
            return true;
        } catch (MalformedURLException ex) {
            return false;
        }
    }
}

Related

  1. isURL(final String urlString)
  2. isURL(Object obj)
  3. isUrl(String input)
  4. isURL(String name)
  5. isURL(String possibleURL)
  6. isUrl(String resourceLocation)
  7. isUrl(String s)
  8. isUrl(String s)
  9. isURL(String str)