我写了一个简单的servlet如下:
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();
}
}
是否需要关闭 PrintWriter
输出流?如果我不关闭流,会不会有进一步的影响?
最佳答案
如果不是您打开流,则不应关闭它。
流由容器打开,因此关闭的责任在于它。
关于java - Servlet PrintWriter 输出流真的需要关闭吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7804339/