How to convert a string to inputstream in Java
To convert a string to inputStream, we can use the ByteArrayInputStream
class in Java.
Here is an example that converts string hello
to inputStream.
import java.io.InputStream;
import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
public class Main
{
public static void main(String[] args) {
String myString = "hello";
InputStream stream = new ByteArrayInputStream(myString.getBytes(StandardCharsets.UTF_8));
System.out.println(stream);
}
}