Java – Convert InputStream to String

This tutorial shows several ways to convert an InputStream to a String in Java.

1- BufferedReader

The common way for generating a String out of an InputStream is through using BufferedReader as the following:

2- Scanner

Another common way is to use a Scanner object as the following:

3- Java 8

With Java 8, you can generate a String out of an InputStream using Collectors and collect() utility method:

4- Apache Commons library

Apart from JDK, you can use Apache Commons library for converting an InputStream to String using 2 ways:

1st way:

2nd way:


0 0 vote
Article Rating

Hussein Terek

Founder of, I have a passion in software engineering and everything related to java environment.

You may also like...

Inline Feedbacks
View all comments