Java Utililty Methods Path to URL

List of utility methods to do Path to URL

Description

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

Method

URLgetURL(String path, URL context)
Given an address and the context (referrer URL/current directory), try to create a URL object.
URL result;
if (context == null) {
    result = resolveFile(new File(path));
    if (result != null)
        return result;
try {
    result = new URL(context, path);
...
URLgetUrl(String pluginId, String relativePath)
Return an URL for the file located within the installation directory of the plug-in that has the given identifier that has the given relative path.
Bundle bundle;
if (pluginId == null || relativePath == null) {
    return null;
bundle = Platform.getBundle(pluginId);
if (bundle != null) {
    return bundle.getEntry(relativePath);
return null;
URLgetURL(String schema, String host, String path)
get URL
URL url = null;
try {
    url = new URL(schema, host, "/" + path);
} catch (MalformedURLException e) {
return url;
URLgetUrl(URL base, String path)
Attempts to return a valid URL from either an absolute 'path' or a relative 'path' combined with 'base'.
URL retVal = null;
if (path != null) {
    try {
        retVal = new URL(path);
    } catch (MalformedURLException mue) {
        retVal = null;
    if (retVal == null && base != null) {
...
URLgetUrlForLocalPath(String path)
get Url For Local Path
return new URL(new java.io.File(path).toURI().toURL().toString()
        + (path.endsWith(java.io.File.separator) ? "/" : ""));
URLgetURLFromClassPath(String source)
get URL From Class Path
if (source.indexOf(":") >= 0)
    source = source.substring(source.indexOf(":"));
return ClassLoader.getSystemResource(source);
URLgetURLFromPath(String jarPath)
get the URL from a given path string
URL jarUrl;
try {
    jarUrl = new URL(jarPath);
} catch (MalformedURLException e) {
    try {
        jarUrl = new URL("file:" + jarPath);
    } catch (MalformedURLException ee) {
        throw new IllegalArgumentException("Unable to find jar:" + jarPath, ee);
...
URLgetUrlFromPath(String path)
get Url From Path
if (isLocalPath(path)) {
    return new File(path).toURI().toURL();
} else {
    return new URL(path);
URLgetUrlFromUrlPath(String path)
get Url From Url Path
try {
    return new URL(path);
} catch (MalformedURLException e) {
    return null;
StringgetURLPath(URI uri)
get URL Path
if (uri.getScheme().equals("module")) {
    return "modules/" + uri.getAuthority() + uri.getPath();
} else {
    return uri.getPath().substring(1);