PrintWriter.flush() does not flush
807580Nov 18 2009 — edited Nov 18 2009I 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?