拷贝InputStream到OutputStream

阅读更多
public static int copy(
  final InputStream input,
  final OutputStream output)
throws IOException {

  final byte[] buffer = new byte[4096];
  int n = 0;
  n = input.read(buffer);
  int total = 0;

  while (-1 != n) {
    output.write(buffer, 0, n);
    total += n;
    n = input.read(buffer);
  }

  return total;
}

你可能感兴趣的:(java)