Here you can find the source of convertStreamToString(InputStream is)
Parameter | Description |
---|---|
is | input stream to convert |
Parameter | Description |
---|---|
IOException | if problems with reading input stream |
public static String convertStreamToString(InputStream is) throws IOException
//package com.java2s; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.StringWriter; public class Main { /**/*from ww w .j a va 2s .c om*/ * Converting input stream content to string * @param is input stream to convert * @return String with stream content * @throws IOException if problems with reading input stream */ public static String convertStreamToString(InputStream is) throws IOException { InputStreamReader r = new InputStreamReader(is); StringWriter sw = new StringWriter(); char[] buffer = new char[1024]; try { for (int n; (n = r.read(buffer)) != -1;) sw.write(buffer, 0, n); } finally { try { is.close(); } catch (IOException e1) { e1.printStackTrace(); } } return sw.toString(); } }