• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating an InputStream from a String

 
Matteo Tassinari
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Convert String into byte array and use ByteArrayInputStream
 
Matteo Tassinari
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then you haven't looked hard. java.lang.String.
 
Matteo Tassinari
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

use below cod eto get the byte array form string
String split = "abe.xyz.pqr" ;
ByteArrayInputStream arrayInputStream = new ByteArrayInputStream( split.getBytes() ) ;
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic