Here you can find the source of getRelativePath(File root, File f)
public static String getRelativePath(File root, File f)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.nio.file.Path; public class Main { public static String getRelativePath(File root, File f) { Path fPath = f.toPath().toAbsolutePath(); Path rootPath = root.toPath().toAbsolutePath(); if (fPath.startsWith(rootPath)) { return fPath.toString().substring(rootPath.toString().length() + 1); } else {// ww w . j av a 2s . c o m throw new IllegalStateException(fPath + " must be located inside " + rootPath); } } }