Resolve a relative URL

import java.net.URL;

public class ResolveRelativeURL {
  public static void main (String[] args) throws
       java.net.MalformedURLException {
    URL relativeURL, baseURL;
    baseURL = new URL ("http://www.rgagnon.com/");
    relativeURL = new URL ( baseURL, "./javadetails/java-0001.html");
    System.out.println ( relativeURL.toExternalForm ());
    /*
      output :
       http://www.rgagnon.com/javadetails/java-0001.html
    */    
  }
}



If you find this article useful, consider making a small donation
to show your support for this Web site and its content.

Written and compiled by Réal Gagnon ©1998-2010
[ home ]