Easy way to write contents of a Java InputStream to an OutputStream

后端 未结 23 2444
粉色の甜心
粉色の甜心 2020-11-22 02:10

I was surprised to find today that I couldn\'t track down any simple way to write the contents of an InputStream to an OutputStream in Java. Obviou

23条回答
  •  -上瘾入骨i
    2020-11-22 03:02

    For those who use Spring framework there is a useful StreamUtils class:

    StreamUtils.copy(in, out);
    

    The above does not close the streams. If you want the streams closed after the copy, use FileCopyUtils class instead:

    FileCopyUtils.copy(in, out);
    

提交回复
热议问题