Here you can find the source of copyFile(File source, File destination)
public static void copyFile(File source, File destination) throws IOException
//package com.java2s; /*//w w w . j av a 2 s . c om * Copyright (c) 2016 Vivid Solutions. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * and Eclipse Distribution License v. 1.0 which accompanies this distribution. * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html * and the Eclipse Distribution License is available at * * http://www.eclipse.org/org/documents/edl-v10.php. */ import java.io.*; public class Main { /** * Copies the source file to the destination filename. * Posted by Mark Thornton <mthorn@cix.compulink.co.uk> on Usenet. */ public static void copyFile(File source, File destination) throws IOException { RandomAccessFile out = new RandomAccessFile(destination, "rw"); //Tell the OS in advance how big the file will be. This may reduce fragmentation out.setLength(source.length()); //copy the content FileInputStream in = new FileInputStream(source); byte[] buffer = new byte[16384]; while (true) { int n = in.read(buffer); if (n == -1) break; out.write(buffer, 0, n); } in.close(); out.close(); } }