java-byte数组的保存姿势
作者:
行走的鸡汤哥 | 来源:发表于
2019-12-29 22:13 被阅读0次public static void main(String[] args) throws IOException {
File file = new File("");
FileInputStream fileInputStream = new FileInputStream(file);
// 用 ByteArrayOutputStream 将byte数组保存到内存中,并通过 toByteArray 方法一次性输出
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
byte[] b = new byte[1024];
int read = 0;
while ((read = fileInputStream.read(b)) > 0) {
byteArrayOutputStream.write(b, 0, read);
}
System.out.println(Base64Util.encode(byteArrayOutputStream.toByteArray()));
}
本文标题:java-byte数组的保存姿势
本文链接:https://www.haomeiwen.com/subject/lupuoctx.html
网友评论