jQuery in Action, 2nd edition*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes PrintWriter after log() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "PrintWriter after log()" Watch "PrintWriter after log()" New topic
Author

PrintWriter after log()

Faisal Ahmad
Ranch Hand

Joined: Aug 31, 2006
Posts: 355

Could you please look into the below code and tell me why PrintWriter object doesn't work when called after writing to log?

Niiraj Patel
Ranch Hand

Joined: Sep 17, 2011
Posts: 47
Hi Faisal,

For the output to be made correctly, PrintWriter object should be flushed and must be closed with its flush() and close() methods.

e.g.
rWriter.flush(); // Writes the remaining data to the screen
rWriter.close(); // Finishes the work

Regards,
Niraj
Faisal Ahmad
Ranch Hand

Joined: Aug 31, 2006
Posts: 355

Hi Niraj!

Thanks so much! So, flushing and closing are must? Why it worked when rWriter was used prior to writing to log?
Niiraj Patel
Ranch Hand

Joined: Sep 17, 2011
Posts: 47

flushing and closing are must?


PrintWriter object should be flushed and must be closed.

flush() should not be necessary but it's good to know that the PrintWriter does not flush before it closes the underlying stream.


Why it worked when rWriter was used prior to writing


PrintWriter has no relation with ServletContext.log()

Regards,
Niraj
Faisal Ahmad
Ranch Hand

Joined: Aug 31, 2006
Posts: 355

Thanks a lot! Will remember it always.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: PrintWriter after log()