Java Path to URL url(String path)

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

Description

url

License

Open Source License

Declaration

public static URL url(String path) throws MalformedURLException 

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 url(String path) throws MalformedURLException {
        //Starts with double backslash, is likely a UNC path
        if (path.startsWith("\\\\")) {
            path = path.replace("\\", "/");
        }//w ww .j a v a2s  . co  m
        return new URL("file:/" + (path.startsWith("/") ? "/" + path : path));
    }
}

Related

  1. toURL(String path)
  2. toURL(String pathPrefix, String jar)
  3. toURLs(String... paths)
  4. toURLs(String[] classPath)
  5. url(final String path)
  6. url(String protocol, String host, int port, String path)