Here you can find the source of getRelativeFilename(File base, File target)
public static String getRelativeFilename(File base, File target)
//package com.java2s; //License from project: LGPL import java.io.File; public class Main { /**/*from ww w . ja va 2 s. c o m*/ * Simplistic version: return the substring after the base */ public static String getRelativeFilename(File base, File target) { return getRelativeFilename(base.getAbsolutePath(), target.getAbsolutePath()); } public static String getRelativeFilename(String sBase, String sTarget) { if (sTarget.startsWith(sBase)) { if (sBase.endsWith("/") || sBase.endsWith("\\") || sTarget.length() == sBase.length()) return sTarget.substring(sBase.length()); else return sTarget.substring(sBase.length() + 1); } else return sTarget; // Leave absolute } }