public static String inputStreamToString ( InputStream x , String encoding ) throws IOException { InputStreamReader in = new InputStreamReader ( x , encoding ) ; StringWriter writer = new StringWriter ( ) ; int blocksize = 8 * 1024 ; char [ ] buffer = new char [ blocksize ] ; for ( ; ; ) { int read = in . read ( buffer ) ; if ( read == - 1 ) { break ; } writer . write ( buffer , 0 , read ) ; } writer . close ( ) ; return writer . toString ( ) ; }
Using a Reader and a Writer returns a String from an InputStream .