You can use Apache Commons IO to handle this and similar tasks.
(您可以使用Apache Commons IO处理此任务和类似任务。)
The IOUtils
type has a static method to read an InputStream
and return a byte[]
.
(IOUtils
类型具有静态方法来读取InputStream
并返回byte[]
。)
InputStream is;
byte[] bytes = IOUtils.toByteArray(is);
Internally this creates a ByteArrayOutputStream
and copies the bytes to the output, then calls toByteArray()
.
(在内部,这将创建一个ByteArrayOutputStream
并将字节复制到输出,然后调用toByteArray()
。)
It handles large files by copying the bytes in blocks of 4KiB. (它通过复制4KiB块中的字节来处理大型文件。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…