Changing a specific byte in a file

I am trying to write a java function that will change 1 byte in a large file. How can I read and write a specific address in a file from java on Android? I tried fis.read (byte b [], int off, int len) and every time I get power.

+3
source share
1 answer

Use RandomAccessFile .

Kickoff example:

 RandomAccessFile raf = new RandomAccessFile(file, "rw"); try { raf.seek(5); // Go to byte at offset position 5. raf.write(70); // Write byte 70 (overwrites original byte at this offset). } finally { raf.close(); // Flush/save changes and close resource. } 
+14
source

Source: https://habr.com/ru/post/917674/


All Articles