Here you can find the source of getRelativePath(File baseDir, File file)
public static String getRelativePath(File baseDir, File file)
//package com.java2s; //License from project: Open Source License import java.io.File; public class Main { public static String getRelativePath(File baseDir, File file) { String basePath = baseDir.getAbsolutePath(); if (!basePath.endsWith(File.separator)) { basePath += File.separator; }//from www . j ava 2 s. co m String filePath = file.getAbsolutePath(); if (!filePath.startsWith(basePath)) { throw new IllegalArgumentException("Not dir-relative: " + filePath + " vs " + basePath); } String relativePath = filePath.substring(basePath.length()); return relativePath; } }