public static String readAsString ( final URL url , final String encoding , final int bufSize ) { try ( final Reader reader = new InputStreamReader ( url . openStream ( ) , encoding ) ) { final StringBuilder sb = new StringBuilder ( ) ; final char [ ] cbuf = new char [ bufSize ] ; int count ; while ( ( count = reader . read ( cbuf ) ) > - 1 ) { sb . append ( String . valueOf ( cbuf , 0 , count ) ) ; } return sb . toString ( ) ; } catch ( final IOException ex ) { throw new RuntimeException ( ex ) ; } }
Reads a given URL and returns the content as String .