Atomically move one file to another file.

@param source the source file.
@param dest the destination file.
@throws IOException if an I/O error occurs.
343066
public static void atomicMove(File source, File dest) throws IOException {
    Files.move(source.toPath(), dest.toPath(), ATOMIC_MOVE, REPLACE_EXISTING);
  }
392045
public function copy($source, $dest)
    {
        // Simple copy for a file
        if (is_file($source)) {
            if (file_exists($dest) && (!empty($this->options['overwrite']) || fileatime($source) < fileatime($dest))) {
                return true;
            }

            return copy($source, $dest);
        }

        // Make destination directory
        if (!is_dir($dest)) {
            @mkdir($dest, 0777, true);
        }

        // Loop through the folder
        $dir = dir($source);
        while (false !== $entry = $dir->read()) {
            // Skip pointers
            if ($entry == '.' || $entry == '..') {
                continue;
            }

            // Deep copy directories
            if ($dest !== "$source/$entry") {
                $this->copy("$source/$entry", "$dest/$entry");
            }
        }

        // Clean up
        $dir->close();

        return true;
    }
357994
public static final void copyResource(String source, Path target, Class<?> cls) throws IOException
    {
        try (InputStream is = cls.getResourceAsStream(source))
        {
            Files.copy(is, target, REPLACE_EXISTING);
        }
    }
305382
@Override
    public T move(String source, String target) throws IllegalArgumentException, IllegalArchivePathException {
        Validate.notNullOrEmpty(source, "The source path was not specified");
        Validate.notNullOrEmpty(target, "The target path was not specified");

        final ArchivePath sourcePath = new BasicPath(source);
        final ArchivePath targetPath = new BasicPath(target);

        return move(sourcePath, targetPath);
    }
18603
protected void copyFile(File src, File dest, Replacement replaceFn) throws IOException {
        boolean isSource = isSourceFile(src);
        copyFile(src, dest, replaceFn, isSource);
    }
438111
public static void copyFile(File sourceFile, File destinationFile) throws FileNotFoundException, IOException {
		Streams.copyStream(new FileInputStream(sourceFile), new FileOutputStream(destinationFile), true);
	}
662615
public static boolean copyFile(File source, File dest) {
		// if(!source.renameTo(new File(dest,source.getName()))) {
		// return false;
		// } else {
		// return true;
		// }
		try {
			FileInputStream in = new FileInputStream(source);
			FileOutputStream out = new FileOutputStream(dest);
			try {
				FileChannel canalFuente = in.getChannel();
				FileChannel canalDestino = out.getChannel();
//				canalFuente.transferTo(0, canalFuente.size(), canalDestino);
				
				long count = 0;
				long size = canalFuente.size();
				while ((count += canalDestino.transferFrom(canalFuente, count,
						size - count)) < size)
					;
			        
			} catch (IOException e) {
				log.error("copiando ficheros orig:'" + source.getAbsolutePath()
						+ "' destino:'" + dest.getAbsolutePath() + "'", e);
				return false;
			} finally {
//				try {
//					in.close();
//				} catch (IOException e) {
//				}
//				try {
//					out.close();
//				} catch (IOException e) {
//				}
				IOUtils.closeQuietly(in);
				IOUtils.closeQuietly(out);
			}
		} catch (FileNotFoundException e) {
			log.error("copiando ficheros orig:'" + source.getAbsolutePath()
					+ "' destino:'" + dest.getAbsolutePath() + "'", e);
			return false;
		}
		return true;
	}
1217610
@SuppressWarnings("resource")
	public static void copy(File src, File dst) throws IOException {

		// Took following recipe from
		// http://stackoverflow.com/questions/106770/standard-concise-way-to-copy-a-file-in-java
		// The nio package seems to be the most efficient way to copy a file
		FileChannel source = null;
		FileChannel destination = null;

		try {
			// we need the supress warnings here (the warning that the stream is not closed is harmless)
			// see http://stackoverflow.com/questions/12970407/does-filechannel-close-close-the-underlying-stream
			source = new FileInputStream(src).getChannel();
			destination = new FileOutputStream(dst).getChannel();
			destination.transferFrom(source, 0, source.size());
		} finally {
			if (source != null) {
				source.close();
			}
			if (destination != null) {
				destination.close();
			}
		}
	}
908378
public static void transferFile(File src, File dest) throws Exception {

        // 删除文件
        // LOGGER.info("start to remove download file: " + ""
        // + dest.getAbsolutePath());
        if (dest.exists()) {
            dest.delete();
        }

        // 转移临时下载文件至下载文件夹
        FileUtils.copyFile(src, dest);
    }
1357077
public static boolean copyFile(final File src, final File dest)
    throws FileNotFoundException, IOException {
        return copyFile(src, dest, -1, true);
    }
1215582
public static void copy(File source, File dest) throws IOException {
        if (dest.isDirectory()) {
            dest = new File(dest + File.separator + source.getName());
        }

        FileChannel in = null, out = null;
        try {
            in = new FileInputStream(source).getChannel();
            out = new FileOutputStream(dest).getChannel();

            long size = in.size();
            MappedByteBuffer buf = in.map(FileChannel.MapMode.READ_ONLY, 0, size);

            out.write(buf);
        } finally {
            if (in != null) {
                in.close();
            }
            if (out != null) {
                out.close();
            }
        }
    }
786070
static void move(File src, File dest) throws IOException {
        try {
            Files.move(src.toPath(), dest.toPath());
        } catch (IOException x) {
            throw x;
        } catch (Exception x) {
            throw new IOException(x);
        }
    }
69931
public function moveImage($source, $dest)
    {
        $this->ftp_mkdir_recur($dest);
        $bool = ftp_put($this->link, $dest, $source, FTP_BINARY);
        if (!$bool) $this->tips = 'move';
        return $bool;
    }
1162691
@Override
    public Node move(Node destNode, boolean overwrite) throws NodeNotFoundException, MoveException {
    	FileNode dest;

        if (!(destNode instanceof FileNode)) {
            return super.move(destNode, overwrite);
        }
        dest = (FileNode) destNode;
        if (!overwrite) {
      	    try {
          		dest.checkNotExists();
          	} catch (IOException e) {
      	    	throw new MoveException(this, dest, "dest exists", e);
      	    }
        }
        try {
            Files.move(path, dest.path, StandardCopyOption.ATOMIC_MOVE);
        } catch (AtomicMoveNotSupportedException e) {
            return super.move(destNode, overwrite);
        } catch (NoSuchFileException e) {
            throw new FileNotFoundException(this, e);
		} catch (IOException e) {
			throw new MoveException(this, dest, "os command failed", e);
		}
        return dest;
    }
1358672
public final static void move(File fromFile, File toFile)
            throws IOException {
        // try the simple way first.
        if (fromFile.renameTo(toFile)) {
            return;
        }

        // copy to the temp file, then rename to the desired name.
        checkThatFileDoesntExist(toFile);
        File tempFile = createTempFile(toFile);
        checkThatFileDoesntExist(tempFile);
        copy(fromFile, tempFile);
        tempFile.renameTo(toFile);
        // delete the old one
        if (!fromFile.delete()) {
            throw new IOException("Failed to delete '" + fromFile.getParent()
                    + "'");
        }
    }
342594
public static void copy(File sourceFile, File targetFile) throws IOException {
	FileInputStream in = new FileInputStream(sourceFile);
	try {
	    FileOutputStream out = new FileOutputStream(targetFile);
	    try {
		copy(in, out);
	    } finally {
		out.close();
	    }
	} finally {
	    in.close();
	}
    }
1253909
public static void copy(FileObject source, FileObject target) throws IOException {
        InputStream in = source.openInputStream();
        OutputStream out = target.openOutputStream();
        try {
            byte[] buffer = new byte[1024];
            int len = in.read(buffer);
            while (len != -1) {
                out.write(buffer, 0, len);
                len = in.read(buffer);
            }
        } finally {
            in.close();
            out.close();
        }
    }