Java BufferedInputStream Copy copyFile(File srcFile, File targetFolder)

Here you can find the source of copyFile(File srcFile, File targetFolder)

Description

copy File

License

Open Source License

Declaration

public static File copyFile(File srcFile, File targetFolder)
            throws IOException 

Method Source Code

//package com.java2s;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

import java.io.IOException;

public class Main {
    public static File copyFile(File srcFile, File targetFolder)
            throws IOException {
        BufferedInputStream bufIn = new BufferedInputStream(
                new FileInputStream(srcFile));

        String targetFilePath = targetFolder.getAbsolutePath()
                + File.separator + srcFile.getName();

        BufferedOutputStream bufOut = new BufferedOutputStream(
                new FileOutputStream(targetFilePath));

        byte[] buf = new byte[1024];
        int cnt = 0;
        while ((cnt = bufIn.read(buf)) != -1) {
            bufOut.write(buf, 0, cnt);/*from w  ww . j ava 2 s  . c o m*/
        }

        bufOut.close();
        bufIn.close();

        return new File(targetFilePath);
    }
}

Related

  1. copyFile(File src, File target)
  2. copyFile(File src, File targetDir, boolean onlyNew)
  3. copyFile(File src, String target)
  4. copyFile(File srcFile, File destFile, boolean createCopy)
  5. copyFile(File srcFile, File detFolder)
  6. copyFile(final File from, final File to)
  7. copyFile(final File fSource, final File fDest)
  8. copyFile(final File source, final File dest, final boolean overwrite)
  9. copyFile(final File source, final File destination)