将字节数组中的内容写入文件,然后将字节从文件中读取回字节数组 [英] write content in a byte array to a file and read the byte from file back to byte array
本文介绍了将字节数组中的内容写入文件,然后将字节从文件中读取回字节数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在不更改之前写入的内容的情况下将字节数组中的内容写入文件并将字节从文件读取回字节数组。在Java
How can write content in a byte array to a file and read the byte from file back to byte array without changing the content written before. in java
推荐答案
在 文件
final Path path myFile = Paths.get("path","to","file");
final byte[] toWrite = ...
Files.write(myFile, toWrite, StandardOpenOption.CREATE_NEW);
final byte[] read = Files.readAllBytes(myFile);
assert Arrays.equals(toWrite, read);
这篇关于将字节数组中的内容写入文件,然后将字节从文件中读取回字节数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文