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

StringgetURLPath(URL repositoryURL)
get URL Path
if ("file".equalsIgnoreCase(repositoryURL.getProtocol())) {
    File folder = new File(repositoryURL.getFile());
    try {
        return (folder.getCanonicalPath());
    } catch (IOException e) {
        return (folder.getAbsolutePath());
} else {
...
StringgetURLPath(URL url)
Builds the path for an URL from path and an optional query
return url.getPath() + (url.getQuery() == null ? "" : "?" + url.getQuery());
StringgetUrlPath(URL url)
get Url Path
return (new File(URLDecoder.decode(url.getPath(), "UTF-8")).getAbsolutePath() + File.separator);
StringgetUrlPath(URL url)
Returns the path portion from the given URL.
StringBuilder buf = new StringBuilder(80);
String tmp;
if ((tmp = url.getPath()) != null) {
    if (!tmp.startsWith("/")) {
        buf.append("/");
    buf.append(tmp);
if ((tmp = url.getQuery()) != null) {
    buf.append("?");
    buf.append(tmp);
if ((tmp = url.getRef()) != null) {
    buf.append("#");
    buf.append(tmp);
return buf.toString();
StringgetURLPathFromURI(String uri)
get URL Path From URI
String path = null;
try {
    URL url = new URL(uri);
    path = url.getPath();
} catch (MalformedURLException e) {
    String urn = fixURN(uri);
    path = getURLPathFromURN(urn);
return path;
StringgetURLPathFromURN(String urn)
get URL Path From URN
String path = null;
URI uri = new java.net.URI(urn);
path = urn.replaceAll("[:]", "/");
return path;
URL[]getURLs(List paths)
get UR Ls
ArrayList<URL> urls = new ArrayList<URL>();
for (String p : paths) {
    urls.add(getURL(p));
return urls.toArray(new URL[urls.size()]);
URL[]getURLs(String thePaths[])
Returns the URLs for given paths.
URL urls[] = new URL[thePaths.length];
for (int i = 0; i < thePaths.length; i++)
    urls[i] = getURL(thePaths[i]);
return urls;
ListgetUrlsFromClassPath(String path)
get Urls From Class Path
List<URL> urls = new ArrayList<>();
try {
    Enumeration<URL> e = ClassLoader.getSystemResources(path);
    while (e.hasMoreElements()) {
        urls.add(e.nextElement());
} catch (IOException e) {
return urls;
StringgetWebDocInfoStr(String urlPath)
Gets the document info string
return urlPath;