Android File Copy copyFile(File aSourceFile, File aTargetFile, boolean aAppend)

Here you can find the source of copyFile(File aSourceFile, File aTargetFile, boolean aAppend)

Description

copy File

Declaration

public static void copyFile(File aSourceFile, File aTargetFile,
            boolean aAppend) throws IOException 

Method Source Code

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

import java.nio.channels.FileChannel;

public class Main {
    public static void copyFile(File aSourceFile, File aTargetFile,
            boolean aAppend) throws IOException {
        FileChannel inChannel = null;
        FileChannel outChannel = null;
        FileInputStream inStream = null;
        FileOutputStream outStream = null;
        try {//from  www.  ja v a 2s  . c  o m
            inStream = new FileInputStream(aSourceFile);
            inChannel = inStream.getChannel();
            outStream = new FileOutputStream(aTargetFile, aAppend);
            outChannel = outStream.getChannel();
            long bytesTransferred = 0;
            // defensive loop - there's usually only a single iteration :
            while (bytesTransferred < inChannel.size()) {
                bytesTransferred += inChannel.transferTo(0,
                        inChannel.size(), outChannel);
            }
        } finally {
            // being defensive about closing all channels and streams
            if (inChannel != null)
                inChannel.close();
            if (outChannel != null)
                outChannel.close();
            if (inStream != null)
                inStream.close();
            if (outStream != null)
                outStream.close();
        }
    }
}

Related

  1. fileCopy(File dbFile, File backup)
  2. fileCopy(File sourcefile, File destinctionFile)
  3. fileCopy(File sourcefile, String destinctionFile)
  4. fileCopy(String sourcefile, String destinctionFile)
  5. bakFile(String source, String dest)
  6. copyFile(File from, File to)
  7. CopyCacheFile(Context con, String assetsFile)
  8. CopyFile(Context con, String assetsFile)
  9. copyFile(File from, File to)