Im trying to write a single byte at a certain location in a file. This is what im using at the moment:
BinaryWriter bw = new BinaryWriter(File.Open(filename, FileMode.Open));
bw.BaseStream.Seek(0x6354C, SeekOrigin.Begin);
bw.Write(0xB0);
bw.Close();
The problem is that BinaryWriter.Write(args) writes a four-byte signed integer at the position. I wish to only write one byte at the particular location. And then later possibly two bytes else where, how I specify how many bytes to write?
There is absolutely no need to use a high-level BinaryWriter just to write a simple byte to a stream – It’s more efficient and tidy just to do this:
(In general you also shouldn’t really Seek after attaching a BinaryWriter to your stream – the BinaryWriter should be in control of the stream, and changing things “behind its back” is a bit dirty)