Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

PrintWriter.flush() does not flush

807580Nov 18 2009 — edited Nov 18 2009
I have a class that acts as combined scanner/parser for the command line interface for a server. The class read and writes through an instance of the Console class obtained by invoking System.console();. For output a PrintWriter associated with the Console is used, obtained by invoking the writer() method of the Console instance.

The class has a method called println that other classes use to write data through. All it does it invoke the println method of the PrintWriter and then the flush method of the PrintWriter.

The problem is that strings outputted in this way are not written to standard out before the close method of the PrintWriter is called even if other text written with the println-flush combination.

How can I get text written without closing the PrintWriter which has to be used in the future?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 16 2009
Added on Nov 18 2009
11 comments
588 views