Here you can find the source of getRelativePath(File baseDir, File file)
public static String getRelativePath(File baseDir, File file)
//package com.java2s; import java.io.File; public class Main { public static String getRelativePath(File baseDir, File file) { if (baseDir.equals(file)) return ""; if (baseDir.getParentFile() == null) return file.getAbsolutePath().substring(baseDir.getAbsolutePath().length()); return file.getAbsolutePath().substring(baseDir.getAbsolutePath().length() + 1); }//from w w w.j a va 2s . c o m }