StringBuffer sb = new StringBuffer(); try { for (String s = null; (s = br.readLine()) != null;) sb.append(s + "\n"); } catch (Exception e) { throw new Exception("Error reading the buffer: " + e.getMessage()); return sb.toString(); ...
StringBuilder result = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { result.append(line).append('\n'); return result.toString();