Java String fromBufferedReader() Utility Method - Converts a BufferedReader into a String

Java String Utility Methods


Java String fromBufferedReader() Utility Method - Converts a BufferedReader into a String.

Java String fromBufferedReader() Utility Method

Converts a BufferedReader into a String.
public static String fromBufferedReader(BufferedReader bufferedReader) {
    StringBuffer sb = new StringBuffer();

    try {
         String line = bufferedReader.readLine();

         while (line != null) {
             sb.append(line);
             line = bufferedReader.readLine();
             if (line != null) {
                  sb.append("\n");
             }
         }
     } catch (IOException e) {
          // replace this with log.error
          e.printStackTrace();
     }

     return sb.toString();
}



Comments