Android File Copy copyFile(String origPath, String destPath)

Here you can find the source of copyFile(String origPath, String destPath)

Description

Convenience function to copy a file.

License

Open Source License

Parameter

Parameter Description
origPath Original path
destPath Destination path

Exception

Parameter Description
IOException If the operation fails during the data copy phase or,FileNotFoundException if either file exists but is a directoryrather than a regular file, does not exist but cannot be read/created,or cannot be opened for any other reason.

Declaration

public static void copyFile(String origPath, String destPath)
        throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import java.nio.channels.FileChannel;

public class Main {
    /**/* ww w.  j  a  v  a2 s.  com*/
     * Convenience function to copy a file.
     * <p>
     * If the destination file exists it is overwritten.
     * 
     * @param origPath Original path
     * @param destPath Destination path
     * @throws IOException If the operation fails during the data copy phase or,
     *             {@link FileNotFoundException} if either file exists but is a directory
     *             rather than a regular file, does not exist but cannot be read/created,
     *             or cannot be opened for any other reason.
     */
    public static void copyFile(String origPath, String destPath)
            throws IOException {
        FileChannel in = null;
        FileChannel out = null;
        try {
            in = new FileInputStream(origPath).getChannel();
            out = new FileOutputStream(destPath).getChannel();
            in.transferTo(0, in.size(), out);
        } finally {
            if (in != null)
                in.close();
            if (out != null)
                out.close();
        }
    }
}

Related

  1. copyFile(File src, File dst)
  2. copyFile(Path source, Path target)
  3. copyFile(String from, String target)
  4. copyFile(String from, String to)
  5. copyFile(String oldPath, String newPath)
  6. copyFile(String sourceFileName, String destinationFileName)
  7. copyFile(String sourcePath, String destPath)
  8. copyFile(String sourcePathName, String destPathName)
  9. copyFile(String srcFile, String destFile)