Here you can find the source of copyStream(InputStream input, OutputStream output)
Parameter | Description |
---|---|
input | The InputStream to be copied to |
output | The target OutputStream to copy to |
Parameter | Description |
---|---|
IOException | If IOException is thrown |
public static String copyStream(InputStream input, OutputStream output) 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 { /**/*ww w . j a va2 s .c o m*/ * Writes the content of input into output * * @param input * The {@link InputStream} to be copied to * @param output * The target {@link OutputStream} to copy to * @return The content of input * @throws IOException * If IOException is thrown */ public static String copyStream(InputStream input, OutputStream output) throws IOException { StringBuilder sb = new StringBuilder(); byte[] buffer = new byte[1024]; int bytesRead; while ((bytesRead = input.read(buffer)) != -1) { output.write(buffer, 0, bytesRead); sb.append(new String(buffer, 0, bytesRead)); } return sb.toString(); } }