1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

writing byte

Discussion in 'C#' started by TinyClone, Apr 17, 2006.

  1. TinyClone

    TinyClone New Member

    Joined:
    Apr 6, 2006
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    0
    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
     
  2. coderzone

    coderzone Super Moderator

    Joined:
    Jul 25, 2004
    Messages:
    734
    Likes Received:
    37
    Trophy Points:
    0
    Actually I could not understand what you are looking for.
     
  3. TinyClone

    TinyClone New Member

    Joined:
    Apr 6, 2006
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    0
    :)

    I looking for code, to write variables to a file, in the way descripbed above
     
  4. coderzone

    coderzone Super Moderator

    Joined:
    Jul 25, 2004
    Messages:
    734
    Likes Received:
    37
    Trophy Points:
    0
    BinaryWriter will do the job for you.

    Here is a simple sample
    Code:
    FileStream  fs = File.Create(Server.MapPath("test.bin"));
    BinaryWriter bw = new BinaryWriter(fs); 
    
    int i = 10; 
    bw.Write(i); 
    
    bw.Close(); 
    fs.Close(); 
     

Share This Page