Java FileInputStream Copy copyFile(File srcFile, File destFile)

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

Description

copy File

License

Open Source License

Declaration

public static void copyFile(File srcFile, File destFile) throws IOException 

Method Source Code

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

import java.io.File;
import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

public class Main {
    public static void copyFile(File srcFile, File destFile) throws IOException {
        FileOutputStream fos = null;
        FileInputStream fis = null;

        try {//from  w  ww.j  av a2 s  . com
            byte[] tempBuff = new byte[10240];

            fis = new FileInputStream(srcFile);
            fos = new FileOutputStream(destFile);

            int readCnt;

            while (true) {
                readCnt = fis.read(tempBuff, 0, tempBuff.length);

                if (readCnt < 0) {
                    break;
                }

                if (readCnt > 0) {
                    fos.write(tempBuff, 0, readCnt);
                    fos.flush();
                }
            }

        } finally {
            try {
                fos.close();
            } catch (Throwable e) {
            }
            try {
                fis.close();
            } catch (Throwable e) {
            }
        }
    }
}

Related

  1. copyFile(File src, File dst)
  2. copyFile(File src, File dst, boolean copyLMD)
  3. copyFile(File src, File target)
  4. copyFile(File src, File toDir)
  5. copyFile(File srcFile, File destFile)
  6. copyFile(File srcFile, File destFile)
  7. copyFile(File srcFile, File destFile)
  8. copyFile(File srcFile, File destFile)
  9. CopyFile(File srcFile, File destFile)