Tuesday, July 6, 2010

JAVA: Convert String to InputStream

You can use ByteArrayInputStream to convert String to InputStream.
ByteArrayInputStream extends InputStream.

Example:
String content = "Convert string to inputstream";
ByteArrayInputStream stream = new ByteArrayInputStream(content.getBytes());



Reference:
1. http://forums.sun.com/thread.jspa?threadID=670188

2. http://java.sun.com/j2se/1.4.2/docs/api/java/io/ByteArrayInputStream.html

1 comment: