Android File Copy copyFile(File from, File to)

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

Description

copy File

Declaration

private static void copyFile(File from, File to) 

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 {
    private static void copyFile(File from, File to) {
        if (!from.exists()) {
            return;
        }/*from   w  w  w  .  jav  a2s.co m*/
        FileInputStream in = null;
        FileOutputStream out = null;
        try {
            in = new FileInputStream(from);
            out = new FileOutputStream(to);

            byte bt[] = new byte[1024];
            int c;
            while ((c = in.read(bt)) > 0) {
                out.write(bt, 0, c);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (in != null) {
                    in.close();
                }
                if (out != null) {
                    out.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
    }
}

Related

  1. copyFile(File aSourceFile, File aTargetFile, boolean aAppend)
  2. copyFile(File from, File to)
  3. CopyCacheFile(Context con, String assetsFile)
  4. CopyFile(Context con, String assetsFile)
  5. copyFile(File from, File to)
  6. copyFile(File sourceFile, File targetFile)
  7. copyFile(String source, String dest)