Java FileChannel Copy copyFiles(File originalFile, File destinationFile)

Here you can find the source of copyFiles(File originalFile, File destinationFile)

Description

copy Files

License

Open Source License

Declaration

public static void copyFiles(File originalFile, File destinationFile)
            throws FileNotFoundException, IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.*;

import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
import java.nio.channels.ReadableByteChannel;

public class Main {
    public static void copyFiles(File originalFile, File destinationFile)
            throws FileNotFoundException, IOException {
        FileInputStream fis = new FileInputStream(originalFile);
        FileOutputStream fos = new FileOutputStream(destinationFile);

        FileChannel inCh = fis.getChannel();
        FileChannel outCh = fos.getChannel();

        outCh.transferFrom(inCh, 0, inCh.size());

        fis.close();/* w w  w  .  j a  va2s . c o m*/
        fos.close();
        inCh.close();
        outCh.close();
    }

    public static void copyFiles(InputStream is, FileOutputStream fos)
            throws IOException {
        ReadableByteChannel inCh = Channels.newChannel(is);
        FileChannel outCh = fos.getChannel();

        outCh.transferFrom(inCh, 0, Integer.MAX_VALUE);

        is.close();
        fos.close();
        inCh.close();
        outCh.close();
    }
}

Related

  1. copyFileIntoProjectFolder(String projectName, File file)
  2. copyFileLocking(File copyFrom, File copyTo)
  3. copyFileNIO(File src, File dest)
  4. copyFileNio(File src, File dst)
  5. copyFileOrDirectory(File source, File destination, boolean flag)
  6. copyFiles(File source, File dest)
  7. copyFiles(File srcFile, File dstFile, boolean overwrite)
  8. copyFiles(final File fromFile, final File toFile)
  9. copyFileToDir(File file, File destDir)