Create relative url in java

Create relative url in java

package com.w3spoint;
 
import java.net.MalformedURLException;
import java.net.URL;
 
public class URLTest {
  public static void main(String args[]){
	try {
		URL baseURL = new URL("https://www.w3schools.blog");
	        URL relativeURL = new URL(baseURL,"/object-oriented-design-principles-in-java-examples/");
                System.out.println(relativeURL.toString());
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
  }
}

Output

https://826.a00.myftpupload.com/object-oriented-design-principles-in-java-examples/
Content Protection by DMCA.com
Please Share