Different Ways to Convert InputStream to String in Java | Code Factory

Reference Link : Link

Donate : Link

CodeFactory.txt

Hello
Code Factory!!!
  1. Convert InputStream to String using BufferedReader

BufferedReaderExample.java

package com.codeFactory;

2. Convert InputStream to String using Scanner

ScannerExample.java

package com.codeFactory;

3. Convert InputStream to String using Stream API Collect

CollectAPIExample.java

package com.codeFactory;

4. Convert InputStream to String using Stream API Parallel

ParallelExample.java

package com.codeFactory;

5. Convert InputStream to String using ByteArrayOutputStream

ByteArrayOutputStreamExample.java

package com.codeFactory;

6. Convert InputStream to String using IOUtils toString

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>

IOUtilsStringExample.java

package com.codeFactory;

7. Convert InputStream to String using IOUtils Copy

IOUtilsCopyExample.java

package com.codeFactory;

8. Convert InputStream to String using Guava CharStreams

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>27.1-jre</version>
</dependency>

GuavaCharStreamsExample.java

package com.codeFactory;

9. Convert InputStream to String using Guava ByteSource

GuavaByteSourceExample.java

package com.codeFactory;