Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to go from StringReader to InputStream?

6 views
Skip to first unread message

bill

unread,
Mar 19, 2002, 4:39:19 PM3/19/02
to


I need to use a class whose constructor takes an InputStream as an
argument. The class uses this InputStream elsewhere to read in data.
I want to provide this data to an instance of this class in the form
of a String (or StringBuffer). The recommended way to read from a
String is to use an instance of the StringReader class, but I have not
been able to find a wrapper class for StringReader to produce an
InputStream. Isn't there a standard way to do this in Java?

Thanks,

bill

P.S. I *did* consult http://mindprod.com/FileIO.html, but it was no
help with this problem. All it told me was to use StringReader, which
I already knew.

Carl Howells

unread,
Mar 19, 2002, 5:11:40 PM3/19/02
to
"bill" <bill...@hotmail.com> wrote...

>
> I need to use a class whose constructor takes an InputStream as an
> argument. The class uses this InputStream elsewhere to read in data.
> I want to provide this data to an instance of this class in the form
> of a String (or StringBuffer). The recommended way to read from a
> String is to use an instance of the StringReader class, but I have not
> been able to find a wrapper class for StringReader to produce an
> InputStream. Isn't there a standard way to do this in Java?

Don't use StringReader. Use ByteArrayInputStream instead. Just use
getBytes(encoding) to convert the String to a byte array, and then use the
byte array as the argument for the ByteArrayInputStream.


0 new messages