Android File Copy copyFile(File sourceFile, File targetFile)

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

Description

copy File

Declaration

public static void copyFile(File sourceFile, File targetFile)
            throws IOException 

Method Source Code

//package com.java2s;

import java.io.*;

public class Main {
    private final static int BUFFER = 8192;

    public static void copyFile(File sourceFile, File targetFile)
            throws IOException {
        BufferedInputStream inBuff = null;
        BufferedOutputStream outBuff = null;
        if (null != sourceFile && null != targetFile) {
            try {
                inBuff = new BufferedInputStream(new FileInputStream(
                        sourceFile));//from w w  w  .ja va2  s.  c  o m
                outBuff = new BufferedOutputStream(new FileOutputStream(
                        targetFile));
                byte[] buffer = new byte[BUFFER];
                int length;
                while ((length = inBuff.read(buffer)) != -1) {
                    outBuff.write(buffer, 0, length);
                }
                outBuff.flush();
            } finally {
                if (inBuff != null) {
                    inBuff.close();
                }
                if (outBuff != null) {
                    outBuff.close();
                }
            }
        }
    }
}

Related

  1. copyFile(File from, File to)
  2. CopyCacheFile(Context con, String assetsFile)
  3. CopyFile(Context con, String assetsFile)
  4. copyFile(File from, File to)
  5. copyFile(File from, File to)
  6. copyFile(String source, String dest)