code: public static String getRelativePath(final File baseDir, final File dir) {
          checkNotNull("baseDir", baseDir);
          checkNotNull("dir", dir);
  
          final String base = getCanonicalPath(baseDir);
          final String path = getCanonicalPath(dir);
          if (!path.startsWith(base)) {
              throw new IllegalArgumentException("The path '" + path + "' is not inside the base directory '" + base + "'!");
          }
          if (base.equals(path)) {
              return "";
          }
          return path.substring(base.length() + 1);
      }
docs: Returns a relative path based on a base directory. If the <code>dir</code> is not inside <code>baseDir</code> an
  <code>IllegalArgumentException</code> is thrown.
  
  @param baseDir
  Base directory the path is relative to - Cannot be <code>null</code>.
  @param dir
  Directory inside the base directory - Cannot be <code>null</code>.
  
  @return Path of <code>dir</code> relative to <code>baseDir</code>. If both are equal an empty string is returned.