Java Path to URL getUrlFromPath(String path)

Here you can find the source of getUrlFromPath(String path)

Description

get Url From Path

License

Apache License

Declaration

public static URL getUrlFromPath(String path) throws MalformedURLException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;

public class Main {
    public static URL getUrlFromPath(String path) throws MalformedURLException {
        if (isLocalPath(path)) {
            return new File(path).toURI().toURL();
        } else {//from  w ww  .  j  a  va 2s  .c  o  m
            return new URL(path);
        }
    }

    public static boolean isLocalPath(String path) {
        try {
            new URL(path);
            return false;
        } catch (MalformedURLException e) {
            return true;
        }
    }
}

Related

  1. getURL(String schema, String host, String path)
  2. getUrl(URL base, String path)
  3. getUrlForLocalPath(String path)
  4. getURLFromClassPath(String source)
  5. getURLFromPath(String jarPath)
  6. getUrlFromUrlPath(String path)
  7. getURLPath(URI uri)
  8. getURLPath(URL repositoryURL)
  9. getURLPath(URL url)