Here you can find the source of copyStream(InputStream in, OutputStream out)
Parameter | Description |
---|---|
in | input stream |
out | output stream |
Parameter | Description |
---|---|
IOException | on error |
public static void copyStream(InputStream in, OutputStream out) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { /**// w ww . j ava2 s.c om * Copy bytes from input to output stream, leaving out stream open * * @param in * input stream * @param out * output stream * @throws IOException * on error */ public static void copyStream(InputStream in, OutputStream out) throws IOException { if (in == null) { throw new NullPointerException("Input stream is null"); } if (out == null) { throw new NullPointerException("Output stream is null"); } final byte[] buf = new byte[2048]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } } }