|
-
May 3rd, 2002, 03:21 PM
#1
Thread Starter
New Member
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
-
May 4th, 2002, 01:30 PM
#2
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++;
}
-
May 4th, 2002, 02:34 PM
#3
Thread Starter
New Member
Thank you
<quote>
BinaryWriter wr=new BinaryWriter(fs)
</quote>
Thank you, it sims to work if I make the struct serializable.
cya
-
May 4th, 2002, 04:51 PM
#4
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|