Here you can find the source of copyStream(BufferedReader reader, BufferedWriter writer)
public static void copyStream(BufferedReader reader, BufferedWriter writer) throws IOException
//package com.java2s; //License from project: Apache License import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.ByteBuffer; import java.nio.channels.Channels; import java.nio.channels.ReadableByteChannel; import java.nio.channels.WritableByteChannel; public class Main { public static void copyStream(BufferedReader reader, BufferedWriter writer) throws IOException { String line = null;//from w w w .ja v a2s . c o m while ((line = reader.readLine()) != null) { writer.write(line); } writer.flush(); } public static void copyStream(final ReadableByteChannel src, final WritableByteChannel dest) throws IOException { final ByteBuffer buffer = ByteBuffer.allocateDirect(16 * 1024); while (src.read(buffer) != -1) { buffer.flip(); dest.write(buffer); buffer.compact(); } buffer.flip(); while (buffer.hasRemaining()) { dest.write(buffer); } } public static void copyStream(InputStream in, OutputStream out) throws IOException { final ReadableByteChannel inputChannel = Channels.newChannel(in); final WritableByteChannel outputChannel = Channels.newChannel(out); copyStream(inputChannel, outputChannel); } }