Ways to convert an InputStream to String

The tutorial show you many ways to convert an InputStream to String, including using Java 8 Stream.

I. Ways to convert an InputStream to a String
1. Using IOUtils

2. Using CharStreams

3. Using Scanner

4. Using StringWriter

5. Using ByteArrayOutputStream

6. Using BufferedInputStream

7. Using Java 8 Stream

The method: java.io.BufferedReader.lines() returns a Stream.

II. Source code

This code is compiled successfully with Java 1.8.

Run code above, the result in console window:


Related Posts



Got Something To Say:

Your email address will not be published. Required fields are marked *

*