Android File 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 {/*from  w w  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. copy(String srcFileName, String destFileName)
  2. copyBundleFile(IPath projectRelativePath, String outputPath)
  3. copyFile(File fin, File fout)
  4. copyFile(File from, File to)
  5. copyFile(File from, File to, boolean append)
  6. copyFile(File in, File out)
  7. copyFile(File source, File dest)
  8. copyFile(File source, File destination)
  9. copyFile(File source, File destination)