Android File Copy copyFile(File in, File out)

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

Description

copy File

Declaration

public static boolean copyFile(File in, File out) 

Method Source Code

//package com.java2s;

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

public class Main {
    public static boolean copyFile(File in, File out) {
        try {//from   w w w  .ja va 2 s. com
            return copyFile(new FileInputStream(in), new FileOutputStream(
                    out));
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    public static boolean copyFile(InputStream in, File out) {
        try {
            return copyFile(in, new FileOutputStream(out));
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    public static boolean copyFile(InputStream input, OutputStream output) {
        try {
            byte[] buf = new byte[1024];
            int len;
            while ((len = input.read(buf)) > 0) {
                output.write(buf, 0, len);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        } finally {
            try {
                if (input != null)
                    input.close();
                if (output != null)
                    output.close();
            } catch (Exception e) {
            }
        }
        return true;
    }
}

Related

  1. copyBundleFile(IPath projectRelativePath, String outputPath)
  2. copyFile(File fin, File fout)
  3. copyFile(File from, File to)
  4. copyFile(File from, File to, boolean append)
  5. copyFile(File from, File to, byte[] buf)
  6. copyFile(File source, File dest)
  7. copyFile(File source, File destination)
  8. copyFile(File source, File destination)
  9. copyFile(File source, File destination)