• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

PrintWriter after log()  RSS feed

 
Ranch Hand
Posts: 355
Chrome Java Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you please look into the below code and tell me why PrintWriter object doesn't work when called after writing to log?

 
Ranch Hand
Posts: 47
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 355
Chrome Java Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 355
Chrome Java Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot! Will remember it always.
 
Don't touch me. And dont' touch this tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!