public static boolean isUnderDirectory ( File child , File parent ) { if ( child == null || parent == null ) return false ; URI childUri = child . toURI ( ) ; URI relativeUri = parent . toURI ( ) . relativize ( childUri ) ; return relativeUri . equals ( childUri ) ? false : true ; }
If child is under parent will return true otherwise return false .