是否真的需要关闭servlet PrintWriter out stream? [英] Does a servlets PrintWriter out stream really need to be closed?

查看:152
本文介绍了是否真的需要关闭servlet PrintWriter out stream?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个简单的servlet如下:

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();
    }
}

是否需要关闭 PrintWriter out stream?如果我不关闭流会影响任何进一步的东西吗?

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.

这篇关于是否真的需要关闭servlet PrintWriter out stream?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆