Android InputStream Copy copyFile(InputStream in, File out)

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

Description

copy File

Declaration

public static boolean copyFile(InputStream 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 {/*www . j a v a2 s . co m*/
            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. copy(InputStream inputStream, OutputStream outputStream)
  2. copy(InputStream pSourceStream, OutputStream pTargetStream)
  3. copy(InputStream pSourceStream, OutputStream pTargetStream, boolean closeSource)
  4. copyContents(InputStream in, OutputStream out)
  5. copyFile(InputStream from, String target)
  6. copyFile(InputStream in, OutputStream out)
  7. copyFile(InputStream input, OutputStream output)
  8. copyStream(InputStream in, OutputStream out)
  9. writeStream(InputStream input, OutputStream output)