public static String readStreamToString ( InputStream is , String encoding ) throws IOException { try { StringBuilder sb = new StringBuilder ( ) ; byte [ ] buf = new byte [ 1024 * 10 ] ; int read ; while ( ( read = is . read ( buf ) ) >= 0 ) { sb . append ( new String ( buf , 0 , read , encoding ) ) ; } return sb . toString ( ) ; } finally { is . close ( ) ; } }
Reads a string from a stream . Closes the stream after reading .