public static String computeFileRelativeLocation ( File rootDirectory , File subFile ) { String rootPath = rootDirectory . getAbsolutePath ( ) ; String subPath = subFile . getAbsolutePath ( ) ; if ( ! subPath . startsWith ( rootPath ) ) throw new IllegalArgumentException ( "The sub-file must be contained in the directory." ) ; if ( rootDirectory . equals ( subFile ) ) throw new IllegalArgumentException ( "The sub-file must be different than the directory." ) ; return subPath . substring ( rootPath . length ( ) + 1 ) . replace ( ' ' , ' ' ) ; }
Computes the relative location of a file with respect to a root directory .