Android File Copy copyFile(File source, File dest)

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

Description

copy File

Declaration

public static void copyFile(File source, File dest) 

Method Source Code

//package com.java2s;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

import java.io.IOException;

public class Main {

    public static void copyFile(File source, File dest) {
        if (!isValidFile(source))
            return;

        FileInputStream in = null;
        FileOutputStream out = null;

        byte[] buffer = new byte[1024 * 64]; //64K
        int bytesRead = -1;
        try {//  ww  w . ja v a  2  s  .com
            in = new FileInputStream(source);
            out = new FileOutputStream(dest);

            while ((bytesRead = in.read(buffer)) != -1) {
                out.write(buffer, 0, bytesRead);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public static boolean isValidFile(String file) {

        return isValidFile(new File(file));
    }

    public static boolean isValidFile(File file) {
        return file.exists() ? file.isFile() : false;
    }
}

Related

  1. copyFile(File fin, File fout)
  2. copyFile(File from, File to)
  3. copyFile(File from, File to, boolean append)
  4. copyFile(File from, File to, byte[] buf)
  5. copyFile(File in, File out)
  6. copyFile(File source, File destination)
  7. copyFile(File source, File destination)
  8. copyFile(File source, File destination)
  9. copyFile(File source, File target)