private static File makeRelative(File filenameToMakeRelative, File rootPath,
			boolean appendCurrentDirectorySymbol) throws IOException {

		if (filenameToMakeRelative == null || rootPath == null) {
			throw new IllegalArgumentException();
		}

		if (!filenameToMakeRelative.isAbsolute()) {
			return filenameToMakeRelative;
		}
		if (!rootPath.isAbsolute()) {
			return filenameToMakeRelative;
		}

		final File root = rootPath.getCanonicalFile();
		final File dir = filenameToMakeRelative.getParentFile().getCanonicalFile();

		final String[] parts1 = split(dir);
		final String[] parts2 = split(root);

		final String relPath = makeRelative(parts1, parts2, filenameToMakeRelative.getName());

		if (appendCurrentDirectorySymbol) {
			return new File(CURRENT_DIRECTORY, relPath);
		}
		return new File(relPath);
	}
private static File makeRelative ( File filenameToMakeRelative , File rootPath , boolean appendCurrentDirectorySymbol ) throws IOException { if ( filenameToMakeRelative == null || rootPath == null ) { throw new IllegalArgumentException ( ) ; } if ( ! filenameToMakeRelative . isAbsolute ( ) ) { return filenameToMakeRelative ; } if ( ! rootPath . isAbsolute ( ) ) { return filenameToMakeRelative ; } final File root = rootPath . getCanonicalFile ( ) ; final File dir = filenameToMakeRelative . getParentFile ( ) . getCanonicalFile ( ) ; final String [ ] parts1 = split ( dir ) ; final String [ ] parts2 = split ( root ) ; final String relPath = makeRelative ( parts1 , parts2 , filenameToMakeRelative . getName ( ) ) ; if ( appendCurrentDirectorySymbol ) { return new File ( CURRENT_DIRECTORY , relPath ) ; } return new File ( relPath ) ; }
Make the given filename relative to the given root path.

@param filenameToMakeRelative is the name to make relative.
@param rootPath is the root path from which the relative path will be set.
@param appendCurrentDirectorySymbol indicates if "./" should be append at the
begining of the relative filename.
@return a relative filename.
@throws IOException when is is impossible to retreive canonical paths.