| Author |
Creating an InputStream from a String
|
Matteo Tassinari
Greenhorn
Joined: Jul 08, 2009
Posts: 6
|
|
Hi everybody
as the topic title suggests, I'd like to see if there is some way to create an InputStream from a String. The only way I've been able to find, searching in the Java API documentation, is to create a StringBufferInputStream, but that's a deprecated class and so I do not really like this method.
Does any of you know if there is another method?
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
|
Convert String into byte array and use ByteArrayInputStream
|
 |
Matteo Tassinari
Greenhorn
Joined: Jul 08, 2009
Posts: 6
|
|
|
And how do I convert a String into a ByteArray? There seems to be no method capable of doing this. Or, at least, I haven't seen it in the API documentation.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
Then you haven't looked hard. java.lang.String.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Matteo Tassinari
Greenhorn
Joined: Jul 08, 2009
Posts: 6
|
|
oh my! I must be blind, I didn't see the getBytes() method!
I completely skipped the initial section, looking for something that sounded like "toByteArray()"... Now I know why I didn't find it!
|
 |
krishna bala
Ranch Hand
Joined: Jul 20, 2009
Posts: 48
|
|
use below cod eto get the byte array form string
String split = "abe.xyz.pqr" ;
ByteArrayInputStream arrayInputStream = new ByteArrayInputStream( split.getBytes() ) ;
|
 |
 |
|
|
subject: Creating an InputStream from a String
|
|
|