Android InputStream Copy copyFile(InputStream input, OutputStream output)

Here you can find the source of copyFile(InputStream input, OutputStream output)

Description

copy File

Declaration

public static boolean copyFile(InputStream input, OutputStream output) 

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.j  a va  2  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 pSourceStream, OutputStream pTargetStream, boolean closeSource)
  2. copyContents(InputStream in, OutputStream out)
  3. copyFile(InputStream from, String target)
  4. copyFile(InputStream in, File out)
  5. copyFile(InputStream in, OutputStream out)
  6. copyStream(InputStream in, OutputStream out)
  7. writeStream(InputStream input, OutputStream output)
  8. CopyStream(InputStream is, OutputStream os)
  9. CopyStream(InputStream is, OutputStream os)