编程语言
首页 > 编程语言> > java – 我应该关闭org.apache.commons.io.IOUtils的InputStream

java – 我应该关闭org.apache.commons.io.IOUtils的InputStream

作者:互联网

我正在使用How to convert InputStream to virtual File上的答案,它使用org.apache.commons.io.IOUtils将给定的InputStream复制到FileOutputStream以创建File.

我应该关闭给出的InputStream吗?

解决方法:

关闭InputStream是最佳做法.见这question.

org.apache.commons.io.IOUtils.copy不关闭流.所以你必须关闭.

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,inputstream,apache-commons-io
来源: https://codeday.me/bug/20190611/1219891.html