将二进制数据存储在".dat"中.或".obj"格式 [英] Storing a binary data in ".dat" or ".obj" format
问题描述
我正在研究ECG仿真项目.我正在从串行端口读取数据并将其存储在数组中.现在,我想以".Dat"和".obj"文件格式存储该二进制数据.任何帮助或想法将不胜感激.
对于i = 1到Station1.mCOMPort.BytesToRead
ReadArray(i)= Convert.ToChar(Station1.mCOMPort.ReadChar)
i
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
推荐答案
请按照以下步骤在.DAT/.OBJ文件中存储二进制数据
1.使用FileStream
创建.dat文件或.obj文件
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.创建BinrayWriter对象以将Binray数据写入.dat/.obj
2. Create BinrayWriter Object to write binray data to .dat / .obj
BinaryWriter binaryfile = new BinaryWriter(myFile);
3.将数组转换为对象
4.将ArrayContent写入文件
3. Convery Array into Object
4. Write the ArrayContent to file
binaryfile.Write(arrayobject);
不要忘记关闭文件
Dont forget to close the files
嗨
如您所要求的将数组转换为对象的示例,请在下面的代码中找到
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());
}
这篇关于将二进制数据存储在".dat"中.或".obj"格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!