Get Relative URL in Java
Description
The following code shows how to get Relative URL.
Example
// w w w . ja v a 2 s .c o m
import java.net.MalformedURLException;
import java.net.URL;
public class Main {
public static void main(String[] a) throws Exception{
URL base = new URL("http://www.java2s.com/");
URL relative = new URL(base, "index.html");
System.out.println(relative);
}
}
The code above generates the following result.