How to easily convert a BufferedReader to a String?

Solution 1:

From Java 8:

rd.lines().collect(Collectors.joining());

Solution 2:

I suggest using commons IO library - then it is a simple 1 liner:

String message = org.apache.commons.io.IOUtils.toString(rd);

of course, be aware that using this mechanism, a denial of service attack could be made, by sending a never ending stream of data that will fill up your server memory.