Convert String to Stream to String

Posted on

In java programming language, String is most widely used class. In certain situations we need to convert String to stream and vice versa. One such scenario is while reading data from a file, we have to convert stream to String. In this blog, we will see how to convert String to Stream and vise versa.You can learn more about String and other classes related with String like StringBuffer and StringBuilder in detail in String in java, StringBuffer in java and StringBuilder in java.

1) Convert String to Stream.

Below code example demonstrate simple way to convert String to Stream using method String.getBytes() and InputStream class.


2) Convert Stream to String.

Below code example demonstrate simple way to convert Stream to String. Helper method is used to generate Stream from String however in practical scenario you don’t need to do so as you have stream as input.


Stay tuned for more tutorials and examples !!!

Leave a Reply

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

Time limit is exhausted. Please reload CAPTCHA.