write content in a byte array to a file and read the byte from file back to byte array

夙愿已清 提交于 2019-12-13 09:37:33

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!