Here you can find the source of getRelativePath(File base, File file)
public static String getRelativePath(File base, File file) throws IOException
//package com.java2s; //License from project: LGPL import java.io.File; import java.io.IOException; public class Main { public static String getRelativePath(File base, File file) throws IOException { String basePath = base.getCanonicalPath(); String filePath = file.getCanonicalPath(); return getRelativePath(basePath, filePath); }/*from ww w . j a v a 2 s. com*/ public static String getRelativePath(String basePath, String filePath) { if (basePath.equals(filePath)) return ""; // Lets consider one type of File Separator. basePath = normalizePath(basePath); filePath = normalizePath(filePath); int beginIndex = filePath.indexOf(basePath); if (beginIndex == -1) return filePath; beginIndex += basePath.length() + 1; return filePath.substring(beginIndex); } public static String normalizePath(String path) { String separator = "/"; return path.replaceAll("\\\\", separator); } }