public static String getText ( BufferedReader reader ) throws IOException { StringBuilder answer = new StringBuilder ( ) ; // reading the content of the file within a char buffer // allow to keep the correct line endings char [ ] charBuffer = new char [ 8192 ] ; int nbCharRead /* = 0*/ ; try { while ( ( nbCharRead = reader . read ( charBuffer ) ) != - 1 ) { // appends buffer answer . append ( charBuffer , 0 , nbCharRead ) ; } Reader temp = reader ; reader = null ; temp . close ( ) ; } finally { closeWithWarning ( reader ) ; } return answer . toString ( ) ; }
Read the content of the BufferedReader and return it as a String . The BufferedReader is closed afterwards .