Here you can find the source of copyFile(File sourceFile, File targetFile)
static public void copyFile(File sourceFile, File targetFile) throws IOException
//package com.java2s; /**/*from ww w .j av a 2s. c o m*/ * Copyright (c) 2010 Ben Fry and Casey Reas * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.opensource.org/licenses/eclipse-1.0.php */ import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { static public void copyFile(File sourceFile, File targetFile) throws IOException { InputStream from = new BufferedInputStream(new FileInputStream(sourceFile)); OutputStream to = new BufferedOutputStream(new FileOutputStream(targetFile)); byte[] buffer = new byte[16 * 1024]; int bytesRead; while ((bytesRead = from.read(buffer)) != -1) { to.write(buffer, 0, bytesRead); } to.flush(); from.close(); // ?? from = null; to.close(); // ?? to = null; targetFile.setLastModified(sourceFile.lastModified()); } }