copy File from InputStream to OutputStream - Android java.io

Android examples for java.io:InputStream

Description

copy File from InputStream to OutputStream

Demo Code

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class Main {

  /**// w w  w . j a  v  a 2  s  .  co m
   * Copy file.
   *
   * @param in
   *          Input file (source).
   * @param out
   *          Output file (destination).
   * @throws IOException
   */
  public static void copyFile(InputStream in, OutputStream out) throws IOException {
    byte[] buffer = new byte[1024];
    int read;
    while ((read = in.read(buffer)) != -1) {
      out.write(buffer, 0, read);
    }
  }

}

Related Tutorials