aspose file tools*
The moose likes Beginning Java and the fly likes Creating an InputStream from a String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Creating an InputStream from a String" Watch "Creating an InputStream from a String" New topic
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: 19720
    
  20

Then you haven't looked hard. java.lang.String.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
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: 61

use below cod eto get the byte array form string
String split = "abe.xyz.pqr" ;
ByteArrayInputStream arrayInputStream = new ByteArrayInputStream( split.getBytes() ) ;
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creating an InputStream from a String