Here you can find the source of copy(File source, File target)
public static void copy(File source, File target) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2012, 2018 Pivotal Software, Inc. * 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:/*from ww w . j a va 2s. c o m*/ * Pivotal Software, Inc. - initial API and implementation *******************************************************************************/ 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 copy(File source, File target) throws IOException { FileInputStream sourceOutStream = new FileInputStream(source); FileOutputStream targetOutStream = new FileOutputStream(target); FileChannel sourceChannel = sourceOutStream.getChannel(); FileChannel targetChannel = targetOutStream.getChannel(); sourceChannel.transferTo(0, sourceChannel.size(), targetChannel); sourceChannel.close(); targetChannel.close(); sourceOutStream.close(); targetOutStream.close(); } }