Android File Copy copyFileToFile(File file, File outFile)

Here you can find the source of copyFileToFile(File file, File outFile)

Description

Copy a file to a location given by another file.

Parameter

Parameter Description
file a parameter
outFile a parameter

Exception

Parameter Description
IOException an exception
FileNotFoundException an exception

Declaration

public static void copyFileToFile(File file, File outFile)
        throws IOException, FileNotFoundException 

Method Source Code

//package com.java2s;
import java.io.*;

public class Main {
    /**//  ww  w .  j  av a 2  s. c  o  m
     * Copy a file to a location given by another file.
     * This makes a backup implicity
     * @param file
     * @param outFile
     * @throws IOException
     * @throws FileNotFoundException
     */
    public static void copyFileToFile(File file, File outFile)
            throws IOException, FileNotFoundException {
        FileInputStream in = new FileInputStream(file);
        FileOutputStream out = new FileOutputStream(outFile);
        byte[] buf = new byte[512];
        int l;
        try {
            while ((l = in.read(buf)) > 0) {
                out.write(buf, 0, l);
            }
            out.flush();
        } catch (IOException e) {
            throw e;
        } finally {
            try {
                out.close();
            } catch (Exception ignored) {
            }
            try {
                in.close();
            } catch (Exception ignored) {
            }
        }
    }
}

Related

  1. copyFile(String sourcePathName, String destPathName)
  2. copyFile(String srcFile, String destFile)
  3. copyFile(String strSrc, String strDest)
  4. copyFileByCommand(String src, String dst, boolean isMove)
  5. copyFileLazy(String source, String destination)
  6. copyFiles(File src, File dst)
  7. copyImgFile(String sourcePath, String fileId)
  8. copyResource(Class cls, String strResSource, String strFile)
  9. copyStringToFile(String content, String FilePath)