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 Answer
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);
FileWriter(String fileName, boolean append)FileOutputStream(File file, boolean append)FileAPI is ancient and should be avoided. See my answer.