• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

close() method

 
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let's say as follow :
{
PrintWriter out =request.getWriter();
response.setContentType("text/html");
out.println("<BODY>etc.....Anything");
out.println("</BODY></HTML>");
}
and

{
PrintWriter out =request.getWriter();
response.setContentType("text/html");
out.println("<BODY>etc.....Anything");
out.println("</BODY></HTML>");
out.close()
}

What is the interst of using the out.close() method...
1/Why have we to use it ?
2/Is it really necessary to close the output ?
3/happens it something on server side if we don't close ?
Thank you.
 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you close a stream, you release the system resources associated with the stream.
Moreover, close() method cause a flushing of the stream. If you do not flush the stream you can not be sure the stream is empty and all the data has been transfered.
As a good practice: close everything you open.
HTH
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The close method does a flush - thats what you really need. If you don't flush you may get no result at all.
Bill
 
I am displeased. You are no longer allowed to read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic