How do I convert string into InputStream?

Here you will find how to convert string into object using class.


import java.nio.charset.StandardCharsets;

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.
        InputStream stream = new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8));