Here you will find how to convert string into java.io.InputStream
object using java.io.ByteArrayInputStream
class.
package org.kodejava.io;
import java.io.*;
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));
}
}
Latest posts by Wayan (see all)
- How do I get the number of processors available to the JVM? - March 29, 2023
- How do I show Spring transaction in log / console? - March 29, 2023
- How do I build simple search page using ZK and Spring Boot? - March 8, 2023