Here you can find the source of getRelativePath(String file, String directory)
public static String getRelativePath(String file, String directory)
//package com.java2s; //License from project: Open Source License import java.nio.file.*; public class Main { public static String getRelativePath(String file, String directory) { Path pathAbsolute = Paths.get(file); Path pathBase = Paths.get(directory); Path pathRelative = pathBase.relativize(pathAbsolute); return pathRelative.toString(); }/*from w w w . j ava 2 s . c o m*/ }