I wrote a simple servlet as follows:
public class MyServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
// [do stuff with the PrintWriter]
out.close();
}
}
Is it necessary to close the PrintWriter out stream? If I don’t close the stream will that affect anything further?
If it’s not you that’s opening the stream, you should not close it.
The stream is opened by the container so the responsibility for closing lies with it.