This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Java in General and the fly likes OutputStream Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "OutputStream" Watch "OutputStream" New topic


Andy Hahn
Ranch Hand

Joined: Aug 31, 2004
Posts: 225
I am using a method that writes it's contents to an output stream.
How can I instead capture those contents into a java String?

Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24166

You can use a ByteArrayOutputStream to collect the data, then use toByteArray() to get the bytes, and then construct a String from them.

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: OutputStream
Similar Threads
OutputStream contents
excel file generation in weblogic portal
reading the content in outputstream
How to transform a OutputStream in a InputStream?
BLOB(image) -> ByteArrayOutputStream -> display on screen