| Author |
Convert a String into a InputStream
|
Tony Evans
Ranch Hand
Joined: Jun 29, 2002
Posts: 521
|
|
Hi I am looking for code examples for converting a String into a Inputstream. Thanks for any help Tony
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24054
|
|
|
new ByteArrayInputStream(theString.getBytes());
|
[Jess in Action][AskingGoodQuestions]
|
 |
Tony Evans
Ranch Hand
Joined: Jun 29, 2002
Posts: 521
|
|
So its InputStream is = new ByteArrayInputStream(AString.getBytes()); Thanks Tony
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24054
|
|
|
Yes.
|
 |
Neeraj Dheer
Ranch Hand
Joined: Mar 30, 2005
Posts: 225
|
|
|
you can also use StringReader and StringWriter
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24054
|
|
Indeed, you can; but not if you want an InputStream.
|
 |
Jim Yingst
Wanderer
Sheriff
Joined: Jan 30, 2000
Posts: 18670
|
|
Note that if you're transferring this data between two different machines, it's usually a good idea to specify what encoding is being used, when sending and receiving. E.g.using String's getBytes(String encoding) method. Do not trust the default platform encoding unless you are sure (a) all the machines involved use the same default encoding, and (b) all the characters in your sting are representable using the default encoding. If you only use characters in US-ASCII (Unicode 0-127) there's usually no problem - at least not until you try to print something that uses Microsoft's "smart quotes" (‘foo’ or “bar” ) rather than "straight" quotes ('foo' or "bar"). [ June 01, 2005: Message edited by: Jim Yingst ]
|
"I'm not back." - Bill Harding, Twister
|
 |
 |
|
|
subject: Convert a String into a InputStream
|
|
|