How do I read / convert an InputStream into a String in Java?
Asked 07 September, 2021
Viewed 2K times
  • 55
Votes

If you have a java.io.InputStream object, how should you process that object and produce a String?


Suppose I have an InputStream that contains text data, and I want to convert it to a String, so for example I can write that to a log file.

What is the easiest way to take the InputStream and convert it to a String?

public String convertStreamToString(InputStream is) {
    // ???
}

30 Answer