Here you can find the source of getRelativePath(File base, File path)
public static String getRelativePath(File base, File path)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.IOException; public class Main { public static String getRelativePath(File base, File path) { try {/*from w w w . java 2 s .co m*/ String relative = base.getCanonicalFile().toURI().relativize(path.getCanonicalFile().toURI()).getPath(); return relative; } catch (IOException e) { return null; } } }