Here you can find the source of writeToStream(InputStream in, OutputStream out, boolean closeOnExit)
public static void writeToStream(InputStream in, OutputStream out, boolean closeOnExit) throws IOException
//package com.java2s; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { public static void writeToStream(InputStream in, OutputStream out, boolean closeOnExit) throws IOException { byte[] bytes = new byte[2048]; for (int c = in.read(bytes); c != -1; c = in.read(bytes)) { out.write(bytes, 0, c);//from w w w .j a v a2s . c om } if (closeOnExit) { in.close(); out.close(); } } }