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 |
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()); } }