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;
import java.io.InputStream;
import java.io.OutputStream;

public class Main {
    public static void copyFile(File srcFile, File destFile) throws IOException {
        FileOutputStream fos = new FileOutputStream(destFile);
        try {//from  w  w w .  j  a  v  a2 s.  co m
            copyToOutputStream(srcFile, fos);
        } finally {
            fos.close();
        }

    }

    public static void copyToOutputStream(File file, OutputStream outputStream) throws IOException {
        InputStream is = new FileInputStream(file);
        try {
            copyToOutputStream(is, outputStream);
        } finally {
            is.close();
        }

    }

    public static void copyToOutputStream(InputStream is, OutputStream os) throws IOException {
        byte[] buffer = new byte[32768];
        while (true) {
            int bytesRead = is.read(buffer);
            if (bytesRead == -1) {
                break;
            }

            os.write(buffer, 0, bytesRead);
        }
    }
}

Related

  1. copyFile(File src, File toDir)
  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)