Results 1 to 4 of 4

Thread: binary/random files

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2002
    Posts
    6

    Question binary/random files

    Hi all!

    I need to write a binary (or random) file with fixed-length structures: I have my struct , an array of type "mystruct", and I have to write/read it from a file.

    I found the stream classes, but work just with base-type or byte-array...

    Some solution?

    Thanx!

    cya

  2. #2
    seljuk
    Guest

    can this information solve your problem

    Code:
    for writing
    FileStream fs=new FileStream(filename,FileMode.Create);
    BinaryWriter wr=new BinaryWriter(fs)
    wr.write(your variable name);
    
    for reading this data
    FileStream fs=new FileStream(filename,FileMode.Open);
    BinaryReader rd=new BinaryReader(fs);
    in this section you must use variable type reading format
    for example if you write an integer value with binarywriter use must use
    rd.ReadInt32();
    command
    or a boolean value use must use rd.ReadBool();
    command;

    for reading all records and assigning them to an array you can make a loop like this

    [CODE]
    i=0;
    while(fs.Position!=fs.Length)
    {
    array[i]=rd.ReadString();// rd.ReadInt32() or rd.ReadDouble()
    i++;
    }

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2002
    Posts
    6

    Thank you

    <quote>

    BinaryWriter wr=new BinaryWriter(fs)

    </quote>


    Thank you, it sims to work if I make the struct serializable.

    cya

  4. #4
    seljuk
    Guest

    No matter


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width