How can I delete a byte if I have its offset from a FileStream and then rewrite it
example:
Offset 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
DB0 00 00 00 00 00 00 01(byte to delete) 00 .......
I tried this but failed :
byte[] newFile = new byte[fs.Length];
fs.Position = 0;
fs.Read(newFile, 0, va -1);
fs.Position = va + 1;
fs.Read(newFile, 0, va + 1);
fs.Close();
fs.Write(newFile, 0, newFile.Length);
Where va is equal to DB5
There are some mistakes in the code:
However, that way of using the
Readmethod is not reliable. The method can actually read less bytes than you request. You need to use the return value from the method call, which is the number of bytes actually read, and loop until you have got the number of bytes that you need: