Here you can find the source of getRelativePath(File rootDirectory, File file)
public static String getRelativePath(File rootDirectory, File file)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.IOException; public class Main { /** Returns the path of {@code file} relative to {@code rootDirectory}. */ public static String getRelativePath(File rootDirectory, File file) { try {/* w ww . j av a2s . co m*/ String rootDir = rootDirectory.getCanonicalPath() + File.separator; String f = file.getCanonicalPath(); if (f.startsWith(rootDir)) { return f.substring(rootDir.length()); } } catch (IOException e) { // fall back to file.getPath() } return file.getPath(); } }