Here you can find the source of getAbsoluteURL(String url, URL base)
public static URL getAbsoluteURL(String url, URL base)
//package com.java2s; import java.net.URL; import java.net.MalformedURLException; public class Main { /**//from ww w .ja v a2 s .c o m *interprets url w.r.t base and returns the corresponding absolute URL (only if url is indeed a relative URL ; returns the original url otherwise) */ public static URL getAbsoluteURL(String url, URL base) { URL res = null; if (url.startsWith("http:") || url.startsWith("file:") || url.startsWith("ftp:")) { //url seems to be an absolute URL try {//try to instantiate it, return null if it fails for some reason res = new URL(url); return res; } catch (MalformedURLException mue) { System.err.println("Error:Utils.getAbsoluteURL():malformed URL: " + url); mue.printStackTrace(); return null; } } else {//url seems to be a relative URL try {//try to interpret it w.r.t base res = new URL(new URL(base.toString().substring(0, base.toString().lastIndexOf("/") + 1)), url); return res; } catch (MalformedURLException mue) { System.err.println("Error:Utils.getAbsoluteURL():malformed URL: " + url); mue.printStackTrace(); return null; } } } }