| Author |
PrintWriter after log()
|
Faisal Ahmad
Ranch Hand
Joined: Aug 31, 2006
Posts: 334
|
posted

0
|
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: 34
|
|
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: 334
|
posted

0
|
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: 34
|
|
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: 334
|
posted

0
|
|
Thanks a lot! Will remember it always.
|
 |
 |
|
|
subject: PrintWriter after log()
|
|
|