Java FileInputStream Copy copyFile(File srcFile, File dstFile)

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

Description

copy File

License

Open Source License

Declaration

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

Method Source Code


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

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

import java.io.FileOutputStream;

public class Main {
    public static void copyFile(File srcFile, File dstFile) throws IOException {
        FileInputStream src = new FileInputStream(srcFile);
        try {//  w  ww.  j  a va2  s  . c o m
            copyFile(src, dstFile);
        } finally {
            src.close();
        }
    }

    public static void copyFile(InputStream src, File dstFile) throws IOException {
        FileOutputStream dst = new FileOutputStream(dstFile);
        byte[] bytes = new byte[65536];
        int count;

        try {
            while ((count = src.read(bytes)) != -1) {
                dst.write(bytes, 0, count);
            }

            dst.flush();

        } finally {
            dst.close();
        }
    }
}

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, boolean recursive)
  6. copyFile(File srcFile, File dstFile)
  7. copyFile(File srcFile, File dstFile)
  8. copyFile(File srcFile, File dstFile)
  9. copyFile(File srcPath, File dstPath)