Java File Copy nio copy(File source, File target)

Here you can find the source of copy(File source, File target)

Description

copy

License

Open Source License

Declaration

public static void copy(File source, File target) throws IOException 

Method Source Code

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

Related

  1. copy(File source, File destination)
  2. copy(File source, File destination)
  3. copy(File source, File destination)
  4. copy(File source, File destination)
  5. copy(File source, File target)
  6. copy(File source, File target)
  7. copy(File source, File target, FilenameFilter filter)
  8. copy(File sourceFile, File destFile)
  9. copy(File sourceFile, File destFile)