Here you can find the source of isDirectoryInPath(File p, File d)
public static boolean isDirectoryInPath(File p, File d)
//package com.java2s; //License from project: LGPL import java.io.File; import java.io.IOException; import java.nio.file.LinkOption; import java.nio.file.Path; import java.nio.file.Paths; public class Main { public static boolean isDirectoryInPath(File p, File d) { try {//from w ww . j av a2 s . c om Path p_ = getAbsolutePath(p); Path d_ = getAbsolutePath(d); return d_.toString().startsWith(p_.toString()); } catch (NullPointerException | IOException e) { return false; } } public static Path getAbsolutePath(File dir) throws IOException { return Paths.get(dir.getPath()).toRealPath(LinkOption.NOFOLLOW_LINKS); } }