public static String relativePath ( File parent , File child ) { Path superPath = parent . toPath ( ) ; Path subPath = child . toPath ( ) ; if ( ! subPath . startsWith ( superPath ) ) { throw new IllegalArgumentException ( "Not a subpath: " + child ) ; } return superPath . relativize ( subPath ) . toString ( ) ; }
Return the relative path between a parent directory and some child path