Here you can find the source of copyFile(File source, File target)
public static void copyFile(File source, File target)
//package com.java2s; /*//from www . j a v a 2 s. c o m * Copyright (c) 2014 Eike Stepper (Berlin, Germany) and others. * All rights reserved. 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.eclipse.org/legal/epl-v10.html * * Contributors: * Eike Stepper - initial API and implementation */ import java.io.Closeable; 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 { public static void copyFile(File source, File target) { int size = (int) source.length(); byte[] buffer = new byte[size]; InputStream in = null; try { in = new FileInputStream(source); in.read(buffer); } catch (IOException ex) { throw new RuntimeException(ex); } finally { close(in); } OutputStream out = null; try { out = new FileOutputStream(target); out.write(buffer); } catch (IOException ex) { throw new RuntimeException(ex); } finally { close(out); } } public static void close(Closeable closeable) { if (closeable != null) { try { closeable.close(); } catch (IOException ex) { ex.printStackTrace(); } } } }