| Refresh | Home EGTry.com

get the absolute url from relative url, relative to the base url


input and output

Base URL relative URL Absolute URL
http://www.egtry.com/home/index.html /image/logo.png http://www.egtry.com/image/logo.png
http://www.egtry.com/home/index.html image/logo.png http://www.egtry.com/home/image/logo.png
http://www.egtry.com/ image/logo.png http://www.egtry.com/image/logo.png
http://www.egtry.com/home/index.html ../image/logo.png http://www.egtry.com/image/logo.png

Code

package net;
import java.net.URL;


public class RelativeURL2Absolute {


	public static void main(String[] args) throws Exception {
		URL baseURL=new URL("http://www.egtry.com/home/index.html");
		URL absoluteURL=new URL(baseURL, "/image/logo.png");
		System.out.println(absoluteURL.toString());
	}

}