读取和写入数据文件 [英] Reading and Wirting data file

查看:92
本文介绍了读取和写入数据文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友们:

我有一个数据文件,每个记录包含3个部分.每个记录的每个部分都粘贴到3个richtextboxes中,然后读取这些textboxes.text并将其以二进制格式写入数据文件,并形成一个记录.
我想打开一个文件并且不读取所有记录,而是查找特定记录,例如,否. 3不读取记录1到2.是否有用于搜索特定字符串的命令?


记录1:
1.一些字符串
2.一些必须以字节为单位写入的图像文件
3.该录音附带一些声音

record2:
1.一些字符串
2.一些必须以字节为单位写入的图像文件
3.该录音附带一些声音

记录3:
1.一些字符串
2.一些必须以字节为单位写入的图像文件
3.该录音附带一些声音

.
.
.

因此,首先,记录的每个部分的长度不是特定的.
其次,如果我关闭文件,并且想将其他记录添加到当前文件中,则必须找到否".最后一条记录,并将其他记录添加到文件中.那么这样做是简单明了的程序吗?

第三,创建记录后应如何修改一条记录?

最后,如果我想加密该文件,其他人是否有可能提取它的内容?

真诚地

Dear My friends:

I have one data file that each record consist of 3 sections. each section of each record paste to 3 richtextboxes and these textboxes.text are read and then write to a data file in the format of binary and forms one record.
I want to open a file and without reading all records, find a specefic record for example no. 3 without reading records 1 to 2. Is there any command for searching a specific string?


record1:
1. some string
2. some image file that must write as bytes
3. some sound attached to this record

record2:
1. some string
2. some image file that must write as bytes
3. some sound attached to this record

record3:
1. some string
2. some image file that must write as bytes
3. some sound attached to this record

.
.
.

so firstly, the lenght of each section of a record is not specific.
secondly, if I close the file, and I want to add some other records to the current file, I must find the no. of last record and add additional records to the file. So is it a straight forward procedure for doing this?

thirdly, how should I modify one record after I create that record?

and finally, if I want to encrypt this file is it possible for others to extract it''s content?

Sincerely

推荐答案

一种方法是针对每条记录,将其转换为二进制,并以字节为单位获取记录的长度.将记录号和记录的长度放在记录前的文件中.这将使您读取记录号,如果不是您想要的记录号,则获得长度,然后将文件中的那么多字节跳过到下一条记录.

至少这是您的第一个问题. :)
One way to do this is for each record, convert to binary, and get the length of the record in bytes. Put that record number and then the length of the record in the file before the record. This will let you read the record number, if it''s not the one you want, you get the length and skip that many bytes in the file to the next record.

That''s at least for your first question. :)


这篇关于读取和写入数据文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆