Here you can find the source of getRelativePath(final File baseDirectory, final File f)
public static String getRelativePath(final File baseDirectory, final File f)
//package com.java2s; /******************************************************************************* * Copyright (c) 2013, 2014, 2015 QPark Consulting S.a r.l. This program and the * accompanying materials are made available under the terms of the Eclipse * Public License v1.0. The Eclipse Public License is available at * http://www.eclipse.org/legal/epl-v10.html. ******************************************************************************/ import java.io.File; public class Main { public static String getRelativePath(final File baseDirectory, final File f) { String s = f.getAbsolutePath(); String base = baseDirectory.getAbsolutePath(); if (s.startsWith(base)) { s = s.substring(base.length()); }/* www. j a v a 2 s.c om*/ return s; } }