Here you can find the source of copyFile(File sourceFile, File targetFile)
public static void copyFile(File sourceFile, File targetFile) throws IOException
//package com.java2s; /*/*from w ww . ja va 2 s . co m*/ * GrGen: graph rewrite generator tool -- release GrGen.NET 4.4 * Copyright (C) 2003-2015 Universitaet Karlsruhe, Institut fuer Programmstrukturen und Datenorganisation, LS Goos; and free programmers * licensed under LGPL v3 (see LICENSE.txt included in the packaging of this file) * www.grgen.net */ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.nio.channels.FileChannel; public class Main { public static void copyFile(File sourceFile, File targetFile) throws IOException { if (!targetFile.exists()) { targetFile.createNewFile(); } FileChannel sourceStream = null; FileChannel targetStream = null; try { sourceStream = new FileInputStream(sourceFile).getChannel(); targetStream = new FileOutputStream(targetFile).getChannel(); long count = 0; long size = sourceStream.size(); while ((count += targetStream.transferFrom(sourceStream, count, size - count)) < size) ; } finally { if (sourceStream != null) sourceStream.close(); if (targetStream != null) targetStream.close(); } } }