Here you can find the source of copyStream(InputStream in, OutputStream out)
Parameter | Description |
---|---|
in | Stream to read from |
out | Stream to write to |
Parameter | Description |
---|---|
IOException | if there is some problem reading or writing |
public static long 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 { private static final int DEFAULT_READ_BUFFER_SIZE = 16 * 1024; /**//w w w. j a v a2 s . c o m * Copies data from one stream to another, until the input stream ends. Uses an * internal 16K buffer. * * @param in Stream to read from * @param out Stream to write to * @return The number of bytes copied * @throws IOException if there is some problem reading or writing */ public static long copyStream(InputStream in, OutputStream out) throws IOException { long total = 0; int len; byte[] buffer = new byte[DEFAULT_READ_BUFFER_SIZE]; while ((len = in.read(buffer)) >= 0) { out.write(buffer, 0, len); total += len; } return total; } }