How do I read / convert an InputStream into a String in Java?
@lebyy▲ 0 net votes
Problem: 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… Fix (from the top answer): To summarize the other answers, I found 11 main ways to do this (see below). And I wrote some performance tests (see results below): Ways to convert an InputStream to a String: Using IOUtils.toString (Apache Utils) String result = IOUtils.toString(inputStream, StandardCharsets.UTF_8); Using CharStreams (Guava) String…