Here you can find the source of relativePath(final URI baseURI, final URI pathURI)
public static String relativePath(final URI baseURI, final URI pathURI)
//package com.java2s; /**//from w w w . ja va 2 s . co m * Copyright (C) 2013 Barchart, Inc. <http://www.barchart.com/> * * All rights reserved. Licensed under the OSI BSD License. * * http://www.opensource.org/licenses/bsd-license.php */ import java.io.File; import java.net.URI; public class Main { /** * Path relative to base. */ public static String relativePath(final String base, final String path) { final URI baseURI = new File(base).toURI(); final URI pathURI = new File(path).toURI(); return baseURI.relativize(pathURI).getPath(); } /** * Path relative to base. */ public static String relativePath(final URI baseURI, final URI pathURI) { return baseURI.relativize(pathURI).getPath(); } }