Here you can find the source of copyFile(File in, File out)
Parameter | Description |
---|---|
in | The source file. |
out | The destination. |
Parameter | Description |
---|---|
IOException | If an I/O exception occurs. |
public static void copyFile(File in, File out) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2009-2010 Red Hat, 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 . ja va 2 s. co m*/ * Red Hat - 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 { /** * Copy file from one destination to another. * @param in The source file. * @param out The destination. * @throws IOException If an I/O exception occurs. */ public static void copyFile(File in, File out) throws IOException { try (FileInputStream fin = new FileInputStream(in); FileChannel inChannel = fin.getChannel(); FileOutputStream fos = new FileOutputStream(out); FileChannel outChannel = fos.getChannel()) { inChannel.transferTo(0, inChannel.size(), outChannel); } } }