Convert InputStream to byte array in Java

前端 未结 30 3523
無奈伤痛
無奈伤痛 2020-11-21 12:08

How do I read an entire InputStream into a byte array?

30条回答
  •  心在旅途
    2020-11-21 12:58

    Java 7 and later:

    import sun.misc.IOUtils;
    ...
    InputStream in = ...;
    byte[] buf = IOUtils.readFully(in, -1, false);
    

提交回复
热议问题