?
Solved

Redirecting the output of a PrintWriter to a StringObject

Posted on 2004-09-22
4
Medium Priority
?
326 Views
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..

Thanx
Novice..Programmer
0
Comment
Question by:FearFactor_x
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 11

Expert Comment

by:cjjclifford
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...)
0
 
LVL 11

Accepted Solution

by:
cjjclifford earned 500 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...
0
 
LVL 12

Expert Comment

by:Giant2
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.
0
 
LVL 12

Expert Comment

by:Giant2
ID: 12121165
Sorry.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
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 …
Suggested Courses

718 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