gpt4 book ai didi

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

转载 作者:IT老高 更新时间:2023-10-28 21:19:18 30 4
gpt4 key购买 nike

Commons-IO有一个 IOUtils.toString(inputStream) 方法,可以从输入流中读取所有内容:

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

我的问题是我应该在使用后手动关闭输入流吗?

我认为IOUtils可能会关闭它,因为它已经读取了所有内容,但我在源代码中找不到。

最佳答案

The 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.

关于java - 使用 commons-io 的 IOUtils.toString(input) 后是否需要手动关闭输入流?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20443179/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com