Convert String to InputStream in Java

In this tutorial, we will learn how to Convert String to InputStream in Java.

While working on Strings, sometimes we come across big String that we want to process it incrementally or a small portion of it at a time. Then in this scenario, converting String to InputStream will be useful.

InputStream is an abstract class representing an input stream of bytes. It implements the Closeable interface. This abstract class is the super class of all classes. Most of the methods in this class will throw an IOException on error conditions.

Let’s see how to Convert String to InputStream with an example.

Example:

Output:

In the above program, we have converted String to InputStream.

Other tutorials: