问题
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
回答1:
There are two methods for exactly this, in Files
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);
来源:https://stackoverflow.com/questions/29508294/write-content-in-a-byte-array-to-a-file-and-read-the-byte-from-file-back-to-byte