Android File Copy copyFile(File source, File destination)

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

Description

copy File

Declaration

public static boolean copyFile(File source, File destination) 

Method Source Code

//package com.java2s;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

import java.nio.channels.FileChannel;

public class Main {
    public static boolean copyFile(File source, File destination) {
        FileInputStream inputStream = null;
        FileOutputStream outputStream = null;
        FileChannel fcin = null;/*from   www .  j a  v a 2  s  .  co m*/
        FileChannel fcout = null;

        try {
            inputStream = new FileInputStream(source);
            outputStream = new FileOutputStream(destination);

            fcin = inputStream.getChannel();
            fcout = outputStream.getChannel();

            long size = fcin.size();

            fcin.transferTo(0L, size, fcout);
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        } finally {
            try {
                if (fcout != null) {
                    fcout.close();
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            try {
                if (fcin != null) {
                    fcin.close();
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            try {
                if (outputStream != null) {
                    outputStream.close();
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            try {
                if (inputStream != null) {
                    inputStream.close();
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }

        return true;
    }
}

Related

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