Here you will find how to convert string into java.io.InputStream
object using java.io.ByteArrayInputStream
class.
package org.kodejava.example.io;
import java.io.*;
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.
try {
InputStream stream = new ByteArrayInputStream(text.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
}
Latest posts by Wayan (see all)
- How do I install Calibri font in Ubuntu? - January 24, 2021
- How do I create a generic class in Java? - January 1, 2021
- How do I convert java.util.TimeZone to java.time.ZoneId? - April 25, 2020