code: public static void copyFile(FileSystem srcFs, Path src, FileSystem dstFs, Path dst, boolean overwrite,
        Configuration conf) throws IOException {
  
      Preconditions.checkArgument(srcFs.isFile(src),
          String.format("Cannot copy from %s to %s because src is not a file", src, dst));
      Preconditions.checkArgument(overwrite || !dstFs.exists(dst),
          String.format("Cannot copy from %s to %s because dst exists", src, dst));
  
      try (InputStream in = srcFs.open(src); OutputStream out = dstFs.create(dst, overwrite)) {
        IOUtils.copyBytes(in, out, conf, false);
      } catch (Throwable t1) {
        try {
          deleteIfExists(dstFs, dst, true);
        } catch (Throwable t2) {
          // Do nothing
        }
        throw t1;
      }
    }
docs: Copy a file from a srcFs {@link FileSystem} to a dstFs {@link FileSystem}. The src {@link Path} must be a file,
  that is {@link FileSystem#isFile(Path)} must return true for src.
  
  <p>
  If overwrite is specified to true, this method may delete the dst directory even if the copy from src to dst fails.
  </p>
  
  @param srcFs the src {@link FileSystem} to copy the file from
  @param src the src {@link Path} to copy
  @param dstFs the destination {@link FileSystem} to write to
  @param dst the destination {@link Path} to write to
  @param overwrite true if the dst {@link Path} should be overwritten, false otherwise