Java FileInputStream Copy copyFile(File from, File to, byte[] buf)

Here you can find the source of copyFile(File from, File to, byte[] buf)

Description

copy File

License

Open Source License

Declaration

public static boolean copyFile(File from, File to, byte[] buf) 

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 {
    private static final int BUFFER_SIZE = 4096 * 4;

    public static boolean copyFile(File from, File to, byte[] buf) {
        if (buf == null)
            buf = new byte[BUFFER_SIZE];

        FileInputStream from_s = null;
        FileOutputStream to_s = null;

        try {// ww  w.j  a va2  s  .  c  o m
            from_s = new FileInputStream(from);
            to_s = new FileOutputStream(to);

            for (int bytesRead = from_s.read(buf); bytesRead > 0; bytesRead = from_s.read(buf)) {
                to_s.write(buf, 0, bytesRead);
            }

            to_s.getFD().sync();

        } catch (IOException ioe) {
            return false;
        } finally {
            if (from_s != null) {
                try {
                    from_s.close();
                    from_s = null;
                } catch (IOException ioe) {

                }
            }
            if (to_s != null) {
                try {
                    to_s.close();
                    to_s = null;
                } catch (IOException ioe) {
                }
            }
        }

        return true;
    }
}

Related

  1. copyFile(File from, File to)
  2. copyFile(File from, File to)
  3. copyFile(File from, File to)
  4. copyFile(File from, File to)
  5. copyFile(File from, File to)
  6. copyFile(File from, File toDir)
  7. copyFile(File from, File toFile)
  8. copyFile(File fromFile, File toFile)
  9. copyFile(File fromFile, File toFile)