Here you can find the source of convertStreamToString(InputStream is)
Parameter | Description |
---|---|
is | the given InputStrem |
Parameter | Description |
---|---|
IOException | if operation fails |
public static String convertStreamToString(InputStream is) throws IOException
//package com.java2s; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; public class Main { /**/*from ww w.j a v a2s. c o m*/ * Convert an InputStream to String * * @param is * the given InputStrem * @return a String * @throws IOException * if operation fails */ public static String convertStreamToString(InputStream is) throws IOException { BufferedReader reader = new BufferedReader( new InputStreamReader(is)); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line).append("\n"); } reader.close(); return sb.toString(); } }