Android File Copy copyFile(String sourcePathName, String destPathName)

Here you can find the source of copyFile(String sourcePathName, String destPathName)

Description

copy File

Declaration

public static void copyFile(String sourcePathName, String destPathName)
            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 av a  2  s. c  o  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(String from, String to)
  2. copyFile(String oldPath, String newPath)
  3. copyFile(String origPath, String destPath)
  4. copyFile(String sourceFileName, String destinationFileName)
  5. copyFile(String sourcePath, String destPath)
  6. copyFile(String srcFile, String destFile)
  7. copyFile(String strSrc, String strDest)
  8. copyFileByCommand(String src, String dst, boolean isMove)
  9. copyFileLazy(String source, String destination)