Click here to Skip to main content
15,886,810 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm working on ECG emulation proj. I'm reading the data from serial port and storing it in an array. now I want to store that binary data in ".Dat" and ".obj" file format. Any help or idea would be appreciated.

For i = 1 To Station1.mCOMPort.BytesToRead
ReadArray(i) = Convert.ToChar(Station1.mCOMPort.ReadChar)
Next i
Posted

Hi follow the below steps to store binary data in .DAT / .OBJ file

1. Create .dat file or .obj file using FileStream
FileStream myFile = File.Create(@"C:\myFile.dat);


2. Create BinrayWriter Object to write binray data to .dat / .obj
BinaryWriter binaryfile = new BinaryWriter(myFile);


3. Convery Array into Object
4. Write the ArrayContent to file

binaryfile.Write(arrayobject);


Dont forget to close the files
 
Share this answer
 
Comments
Md Athaulla 9-Aug-10 5:50am    
Thanks for your reply Rajesh. Could u please give me one example, converting array to objects??
Hi
As you asked sample for converting array to objects, pls find the below the code

string[] Names = {"Rajesh","Praveen","Kiran","Arun" };
Object _obj;
foreach (String strnames in Names)
           {
               _obj = strnames.ToString();
               MessageBox.Show(_obj.ToString());
           }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900