copy from InputStream to OutputStream - Android android.view.inputmethod

Android examples for android.view.inputmethod:KeyBoard

Description

copy from InputStream to OutputStream

Demo Code

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

public class Main {

  public static void copy(InputStream in, OutputStream out) throws IOException {
    byte[] buffer = new byte[1024 * 32];
    int read;/*  ww w  .  j  a  v  a 2 s  .com*/
    while ((read = in.read(buffer)) != -1) {
      out.write(buffer, 0, read);
    }
  }

  public static void copy(File src, File dst) throws IOException {
    InputStream in = null;
    OutputStream out = null;
    try {
      in = new FileInputStream(src);
      out = new FileOutputStream(dst);
      copy(in, out);
    } catch (IOException ex) {
      throw ex;
    } finally {
      close(in);
      close(out);
    }
  }

  public static void close(Closeable closeable) {
    try {
      if (closeable != null) {
        closeable.close();
      }
    } catch (Exception x) {
      // Ignored
    }
  }

}

Related Tutorials