Here you can find the source of concatUrl(final URL baseUrl, final String extraPath)
public static URL concatUrl(final URL baseUrl, final String extraPath)
//package com.java2s; import java.net.URI; import java.net.URL; public class Main { public static URL concatUrl(final URL baseUrl, final String extraPath) { try {// w w w. j a v a 2 s. co m URI uri = baseUrl.toURI(); String newPath = uri.getPath() + (uri.getPath().endsWith("/") ? "" : "/") + extraPath; URI newUri = uri.resolve(newPath); return newUri.toURL(); } catch (Exception e) { throw new RuntimeException("Can't add extra path " + extraPath + " to url " + baseUrl, e); } } }