Here you can find the source of copyStream(InputStream input, OutputStream output)
Parameter | Description |
---|---|
IOException | an exception |
public static void copyStream(InputStream input, OutputStream output) throws IOException
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { public static final int DEFAULT_BUFFER_SIZE = 8192; /** Copy the data from an {@link InputStream} to an {@link OutputStream} without closing the stream. * @throws IOException *//* ww w .ja v a 2 s.c o m*/ public static void copyStream(InputStream input, OutputStream output) throws IOException { copyStream(input, output, DEFAULT_BUFFER_SIZE); } /** Copy the data from an {@link InputStream} to an {@link OutputStream} without closing the stream. * @throws IOException */ public static void copyStream(InputStream input, OutputStream output, int bufferSize) throws IOException { byte[] buffer = new byte[bufferSize]; int bytesRead; while ((bytesRead = input.read(buffer)) != -1) { output.write(buffer, 0, bytesRead); } } }