Java FileInputStream Copy CopyFile(File srcFile, File destFile)

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

Description

Copy File

License

Apache License

Declaration

public static void CopyFile(File srcFile, File destFile) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class Main {
    public static void CopyFile(File srcFile, File destFile) {
        try {/*from   w w w . j  a  va 2s  . c  om*/
            int bytesum = 0;
            int byteread = 0;
            InputStream inStream = new FileInputStream(srcFile);
            FileOutputStream fs = new FileOutputStream(destFile);
            byte[] buffer = new byte[1444];
            while ((byteread = inStream.read(buffer)) != -1) {
                bytesum += byteread;
                fs.write(buffer, 0, byteread);
            }
            inStream.close();
            fs.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void CopyFile(String srcFile, String destFile) {
        try {
            File src = new File(srcFile);
            File dest = new File(destFile);
            if (!dest.exists()) {
                dest.createNewFile();
                CopyFile(src, dest);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Related

  1. copyFile(File srcFile, File destFile)
  2. copyFile(File srcFile, File destFile)
  3. copyFile(File srcFile, File destFile)
  4. copyFile(File srcFile, File destFile)
  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)