本文介绍三种将InputStream转成Byte数组的方法:
只使用JDK
固定大小的stream
1 | InputStream initialStream = new ByteArrayInputStream(new byte[] {0, 1, 2}); |
不固定大小的stream
1 | InputStream is = new ByteArrayInputStream(new byte[] {0, 1, 2}); |
使用Guava
1 | InputStream initialStream = ByteSource.wrap(new byte[] {0, 1, 2}).openStream(); |
使用Commons IO
1 | ByteArrayInputStream initialStream = new ByteArrayInputStream(new byte[] {0, 1, 2}); |
http://www.baeldung.com/convert-input-stream-to-array-of-bytes