• Post Reply Bookmark Topic Watch Topic
  • New Topic

Convert String to an InputStream

 
Chandhrasekar Saravanan
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai,
how can i convert an string in to an InputStream, as InputStreams are byte oriented how is it possible. I checked java InputSteam API but i couldnt get an idea .
 
Chris Stehno
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The solution is not too bad, just not very obvious ... try this...
String yourString = "This is a string!";
ByteArrayInputStream bais = new ByteArrayInputStream(yourString.getBytes());
InputStream inStream = bais;
That should do the trick.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!