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 create a string of repeated characters? - September 1, 2023
- How do I convert datetime string with optional part to a date object? - August 28, 2023
- How do I split large excel file into multiple smaller files? - April 15, 2023