How do I convert string into InputStream?

Here you’ll find how to convert string into InputStream object using ByteArrayInputStream class.



public class StringToStream {
    public static void main(String[] args) {
        String text = "Converting String to InputStream Example";
         * Convert String to InputStream using ByteArrayInputStream 
         * class. This class constructor takes the string byte array 
         * which can be done by calling the getBytes() method.
        try {
            InputStream is = new ByteArrayInputStream(text.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {

Wayan Saryada

A programmer, runner, recreational diver, currently living in the island of Bali, Indonesia. Mostly programming in Java, creating web based application with Spring Framework, JPA, etc. If you need help on Java programming you can hire me on Fiverr.

Leave a Reply