简体   繁体   English

在使用commons-io的IOUtils.toString(输入)后,是否需要手动关闭输入流?

[英]Do I need to close the input stream manually after using IOUtils.toString(input) of commons-io?

Commons-IO has an IOUtils.toString(inputStream) method, which can read all content from an input stream: Commons-IO有一个IOUtils.toString(inputStream)方法,它可以读取输入流中的所有内容:

InputStream input = getInputStream();
String content = IOUtils.toString(input);

My question is shall I close the input stream manually after using it? 我的问题是我在使用后手动关闭输入流吗?

I thought IOUtils may close it since it has read all the content, but I can't find that in the source code. 我以为IOUtils可能会关闭它,因为它已经阅读了所有内容,但我在源代码中找不到它。

The javadoc says: javadoc说:

Wherever possible, the methods in this class do not flush or close the stream. 只要有可能,此类中的方法不会刷新或关闭流。 This is to avoid making non-portable assumptions about the streams' origin and further use. 这是为了避免对流的来源和进一步使用做出不可移植的假设。 Thus the caller is still responsible for closing streams after use. 因此,呼叫者仍然负责在使用后关闭流。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM