I want to write a ~20000 bytes to a replace the same number of bytes of file at offset OFFSET using a BufferedOutputStream. I try to do this with the following code:
headerOffset = 12000;
headerSize = 20000;
byte[] ba = new byte[20];
FileOutputStream os;
BufferedOutputStream bos;
try {
os = new FileOutputStream('file.dat');
bos = new BufferedOutputStream(os);
bos.write(ba, headerOffset, headerSize);
os.flush();
} catch (IOException e) { e.printStackTrace(); }
However, this results in the 'file.dat' being overwritten by the contents of ba overwriting the entire file and leaving it only as big as ba
. What am I doing wrong?