writing byte

TinyClone's Avatar, Join Date: Apr 2006
Go4Expert Member
Im trying to write some come but it isnt coming along. This is what i have/want:


int[] myIntArray
int[] myintArray2
Bitmap myBitmap
// All of these have some value(s)
// I want to write them to a file using this protocol (byte sizes are fixed):
(4 bytes) Size of myIntArray
(4 bytes) Position of myIntArray in the file
(4 bytes) Size of myIntArray2
(4 bytes) Position of myIntArray2 in the file
(4 bytes) Size of myBitmap
(4 bytes) Position of myBitmap in the file
(lots of bytes, 4 per element) myIntArray
(lots of bytes, 4 per element) myIntArray2
(lots of bytes, preferably PNG fromat) myBitmap


I'd really apreciate any help
coderzone's Avatar, Join Date: Jul 2004
Team Leader
Actually I could not understand what you are looking for.
TinyClone's Avatar, Join Date: Apr 2006
Go4Expert Member


I looking for code, to write variables to a file, in the way descripbed above
coderzone's Avatar, Join Date: Jul 2004
Team Leader
BinaryWriter will do the job for you.

Here is a simple sample
Code: C#
FileStream  fs = File.Create(Server.MapPath("test.bin"));
BinaryWriter bw = new BinaryWriter(fs);

int i = 10;
bw.Write(i);

bw.Close();
fs.Close();