//将字节数组写入data.bin文件
byte[] b = {1,2};
try {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
DataOutputStream os = new DataOutputStream(
new BufferedOutputStream(new FileOutputStream(
"D:\\Users\\data.bin")));
log.info(":{}",b);
os.write(b);
os.flush();
os.close();
} catch (IOException e) {
e.printStackTrace();
}
//读取data.bin文件中的数据
try {
DataInputStream is = new DataInputStream(
new BufferedInputStream(new FileInputStream(
"D:\\Users\\data.bin")));
byte[] c =new byte[2];
is.read(c);
is.close();
log.info(":{}",c);
} catch (IOException e) {
e.printStackTrace();
}
在路径下生成了data.bin文件
日志
2019-08-14 18:20:42.949 [http-nio-8092-exec-1] INFO ServiceImpl - :[1, 2]
2019-08-14 18:20:42.950 [http-nio-8092-exec-1] INFO ServiceImpl - :[1, 2]