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

拟墨画扇 提交于 2019-11-30 00:16:34

问题


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?

I thought IOUtils may close it since it has read all the content, but I can't find that in the source code.


回答1:


The javadoc says:

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.



来源:https://stackoverflow.com/questions/20443179/do-i-need-to-close-the-input-stream-manually-after-using-ioutils-tostringinput

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!