Google+

Wednesday, September 14, 2011

How to Convert InputStream to String In Java

Here is the Simple method to convert InputStream Object to String Object.


Just Call this method and pass InputStream Object. it return the String






public static String convertStreamToString(InputStream is) throws Exception
{
    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
    StringBuilder sb = new StringBuilder();
    String line = null;

    while ((line = reader.readLine()) != null) {
        sb.append(line);
    }

    is.close();

    return sb.toString();
}

No comments:

Google+