public static void copyReader ( OutputStream outs , Reader reader ) throws IOException { try { OutputStreamWriter writer = new OutputStreamWriter ( outs , StandardCharsets . UTF_8 ) ; char [ ] bytes = new char [ 1024 ] ; int r = reader . read ( bytes ) ; while ( r > 0 ) { writer . write ( bytes , 0 , r ) ; r = reader . read ( bytes ) ; } } catch ( IOException e ) { throw e ; } finally { reader . close ( ) ; } }
Copy the reader to the output stream