Here you can find the source of copyFile(File src, File target)
public static void copyFile(File src, File target) throws IOException
//package com.java2s; /*//from w w w .j a v a2 s . c o m * Copyright (C) ${year} Omry Yadan <${email}> * All rights reserved. * * See https://github.com/omry/banana/blob/master/BSD-LICENSE for licensing information */ import java.io.*; public class Main { public static void copyFile(File src, File target) throws IOException { BufferedInputStream in = null; BufferedOutputStream out = null; try { in = new BufferedInputStream(new FileInputStream(src)); out = new BufferedOutputStream(new FileOutputStream(target)); pump(in, out); } finally { if (in != null) try { in.close(); } catch (IOException e) { } if (out != null) try { out.close(); } catch (IOException e) { } } } /** * Writes the bytes read from the given input stream into the given output * stream until the end of the input stream is reached. Returns the amount of * bytes actually read/written. */ public static int pump(InputStream in, OutputStream out) throws IOException { byte[] buf = new byte[4096]; int count; int amountRead = 0; while ((count = in.read(buf)) != -1) { out.write(buf, 0, count); amountRead += count; } return amountRead; } }