在使用commons-io的IOUtils.toString(输入)后,是否需要手动关闭输入流? [英] Do I need to close the input stream manually after using IOUtils.toString(input) of commons-io?
问题描述
Commons-IO 有一个 IOUtils.toString(inputStream)
方法,它可以读取输入流中的所有内容:
Commons-IO has an IOUtils.toString(inputStream)
method, which can read all content from an input stream:
InputStream input = getInputStream();
String content = IOUtils.toString(input);
我的问题是我在使用后手动关闭输入流吗?
My question is shall I close the input stream manually after using it?
我认为IOUtils可能会关闭它,因为它已经阅读了所有内容,但我在源代码中找不到它。
I thought IOUtils may close it since it has read all the content, but I can't find that in the source code.
推荐答案
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.
这篇关于在使用commons-io的IOUtils.toString(输入)后,是否需要手动关闭输入流?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!