Redirecting the output of a PrintWriter to a StringObject

Posted on 2004-09-22
Last Modified: 2012-08-13
hi Experts,
             I need to redirect the Output of a printwriter to a String object. It is not possbile to write to a file and read that file bcos i am Writing BLOB Ojects from a database. Is there any way to do this..

Question by:FearFactor_x
  • 2
  • 2
LVL 11

Expert Comment

ID: 12121117
Use a PipedOutputStream as the Output for the PrintWriter, and read the data from the associated PipedInputStream (possibly using a StringWriter to build the string...)
LVL 11

Accepted Solution

cjjclifford earned 125 total points
ID: 12121125
Or even simpler, use a ByteArrayOutputStream with the PrintWriter, and use the "toString()" method after the final flush()/close() on the PrintWriter to convert the ByteArray to a String...
LVL 12

Expert Comment

ID: 12121153
I suggest to use the Stream to write and read the data because if the data are really big there could be some problem.
So, write to the OutputStream and read from the InputStream (like loopback).
Hope this could help.
Bye, Giant.
LVL 12

Expert Comment

ID: 12121165

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question