Java FileChannel Copy copyFile(File in, File out)

Here you can find the source of copyFile(File in, File out)

Description

Copy file from one destination to another.

License

Open Source License

Parameter

Parameter Description
in The source file.
out The destination.

Exception

Parameter Description
IOException If an I/O exception occurs.

Declaration

public static void copyFile(File in, File out) throws IOException 

Method Source Code

//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);
        }
    }
}

Related

  1. copyFile(File from, File to)
  2. copyFile(File from, File to)
  3. copyFile(File from, File to)
  4. copyFile(File from, File to)
  5. copyFile(File from, File to, long fromoffset, long tooffset, long size)
  6. copyFile(File in, File out)
  7. copyFile(File in, File out)
  8. copyFile(File in, File out)
  9. copyFile(File in, File out)