code: public static File computeRelativeFile(File file, File rel, File dir) {
          String path = file.getAbsolutePath();
          String relativePath = path.substring(rel.getAbsolutePath().length());
          return new File(dir, relativePath);
      }
docs: Gets a File object representing a File in the directory <tt>dir</tt> which has the same path as the file
  <tt>file</tt> from the directory <tt>rel</tt>.
  <p>
  For example, copying root/foo/bar.txt to out with rel set to root returns the file out/foo/bar.txt.
  
  @param file the file to copy
  @param rel  the base 'relative'
  @param dir  the output directory
  @return the destination file