Here you can find the source of relativize(URI baseURI, URI uriToRelativize)
public static URI relativize(URI baseURI, URI uriToRelativize)
//package com.java2s; import java.io.*; import java.net.*; public class Main { public static URI relativize(URI baseURI, URI uriToRelativize) { URI relativizedURI;/* w w w.java 2 s .c o m*/ if (baseURI == null) { relativizedURI = uriToRelativize; } else { try { File file = new File(baseURI); if (!file.isDirectory()) { File parent = file.getParentFile(); baseURI = parent.toURI(); } } catch (IllegalArgumentException e) { // do nothing, not a file uri } relativizedURI = baseURI.relativize(uriToRelativize); } return relativizedURI; } }