Here you can find the source of relativeFileName(final File baseDir, final File file)
public static String relativeFileName(final File baseDir, final File file)
//package com.java2s; //License from project: Apache License import java.io.File; public class Main { public static String relativeFileName(final File baseDir, final File file) { final String basePath = baseDir.getAbsolutePath(); final String filePath = file.getAbsolutePath(); if (baseDir.isDirectory() && file.isFile() && filePath.startsWith(basePath)) { // +1 to rid of starting '/' return filePath.substring(basePath.length() + 1); } else {/*from w ww . j a v a2 s.c o m*/ return filePath.substring(1); } } }