Android File Copy copyFile(File sourceFile, File destFile)

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

Description

copy File

Declaration

public static void copyFile(File sourceFile, File destFile)
            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 sourceFile, File destFile)
            throws IOException {
        if (!destFile.exists()) {
            destFile.createNewFile();//from   ww w .  j a  v  a 2 s .co  m
        }

        FileChannel source = null;
        FileChannel destination = null;
        try {
            source = new FileInputStream(sourceFile).getChannel();
            destination = new FileOutputStream(destFile).getChannel();
            destination.transferFrom(source, 0, source.size());
        } finally {
            if (source != null) {
                source.close();
            }
            if (destination != null) {
                destination.close();
            }
        }
    }

    public static void copyFile(String sourcePathName, String destPathName)
            throws IOException {
        copyFile(new File(sourcePathName), new File(destPathName));
    }
}

Related

  1. copyFile(File source, File dest)
  2. copyFile(File source, File destination)
  3. copyFile(File source, File destination)
  4. copyFile(File source, File destination)
  5. copyFile(File source, File target)
  6. copyFile(File src, File dest)
  7. copyFile(File src, File dst)
  8. copyFile(Path source, Path target)
  9. copyFile(String from, String target)