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 number of each day for a certain month in Java? - September 8, 2024
- How do I get operating system process information using ProcessHandle? - July 22, 2024
- How do I sum a BigDecimal property of a list of objects using Java Stream API? - July 22, 2024