如何将字节数组中的内容写入文件,并将文件中的字节读回字节数组,而不更改之前写入的内容。在java中
答案 0 :(得分:1)
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);