reading an writing bytes into a file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • swts
    New Member
    • Feb 2008
    • 16

    #1

    reading an writing bytes into a file

    hi, i have a structure wid a byte array member
    [code=c]
    public struct pack
    { public byte[] data;
    /*...*/
    }[/code]

    and i have an array of packets
    the following code works fine:
    [code=cpp]
    FileStream inStream = File.OpenRead(" some file name");
    FileStream outStream = File.OpenWrite( "some filename");
    int bytesRead;
    byte[] buf = new byte[4096];
    int num_pac=0;

    while ((bytesRead = inStream.Read(b uf, 0, 4096)) > 0)
    { pkt[i].data=buf;
    outStream.Write (pkt[i].data, 0, 4096);
    num_pac++;
    }
    [/code]
    however when i write the file seperately i get the followin error
    [code=cpp]
    for(int j=0;j<num_pac;j ++)
    { outStream.Write (pkt[j].data, 0, 4096);}
    [/code]
    can someone suggest a solution?
    thanks in advance
    Last edited by Frinavale; Apr 30 '08, 06:19 PM. Reason: added [code] tags
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    What error? You never said what the error is that you got.
    I would guess that you are rying to read/write more bytes then there are available.

    Comment

    Working...