How to convert an InputStream to a string in Java
This below example will show you how to convert an InputStream
to a String
by using apache commons IOUtils class.
String myString = IOUtils.toString(myInputStream, "UTF-8");
Where UTF-8
is a character encoding.
Similarly, you can also use the CharStreams
Guava.
String myString = CharStreams.toString(new InputStreamReader(
inputStream, Charsets.UTF_8));