How do I convert string into InputStream?
Category: java.io, viewed: 2365 time(s).
Here you'll find how to convert string into InputStream object using ByteArrayInputStream class.
package org.kodejava.example.io; import java.io.ByteArrayInputStream; import java.io.InputStream; public class StringToStream { public static void main(String[] args) { String text = "Converting String to InputStream Example"; /* * Convert String to InputString using ByteArrayInputStream class. * This class constructor takes the string byte array which can be * done by calling the getBytes() method. */ try { InputStream is = new ByteArrayInputStream(text.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } } |
Can't find what you are looking for? Join our FORUMS and ask some questions!
Related Examples
- How do I store properties as XML file?
- How do I load properties from XML file?
- How do I convert InputStream to String?
- How do I get an exception stack trace message?
- How do I use Console class to read user input?
- How do I store objects in file?
- How do I use DataInputStream and DataOutputStream?
- How do I use RandomAccessFile class?
- How do I create a directories recursively?
- How can I get current working directory?