This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

close() method  RSS feed

 
Engin Okucu
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • 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.
 
Juanjo Bazan
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • 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
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • 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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!