如何从二进制写入器写入的数据文件(没有字符串和整数)中读取特定字符串 [英] how to read a specific string from a data file (having no. of strings and integers) written with binary writer

查看:76
本文介绍了如何从二进制写入器写入的数据文件(没有字符串和整数)中读取特定字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Everyone,


在我的项目中,我有一个用二进制编写器编写的数据文件(没有字符串和整数)。现在我想从该文件中读取一个特定的字符串,该文件位于该文件之间,我也想读取该文件中该字符串的位置。


现在问题我不知道我不知道怎么做


所以请帮我这个......

解决方案


现在我想读取该文件中的特定字符串,该文件位于该文件之间,我还想读取该文件中该字符串的位置。


如果文件是使用二进制格式编写的,那么通常会读取整个文件并使用与将字符串插入二进制数据的过程相反的方法提取所需的字符串例如,如果您使用了类实例的序列化,那么您将通过反序列化从文件中重新创建类实例,并将该字符串作为属性或已创建的类实例的字段。


如果您编写了一系列二进制数据项,那么您将阅读相同系列的数据项,直到您获得所需的字符串为止。 如果您知道(或可以计算)字符串数据的文件偏移量,您可以从该偏移量开始读取。


因此,您阅读的起点将是您用来执行此操作的代码。 。写作 您需要显示该代码。



Hello Everyone,

in my project i have an data file(having no. of strings and integers)written with binary writer. Now i want to read a specific string from that file which is somewhere in between that file and i also want to read the position of that string in the file.

now the problem that i don't know how to do that

So please help me with this...

解决方案

Now i want to read a specific string from that file which is somewhere in between that file and i also want to read the position of that string in the file.

If the file was written using a binary format then you would usually read the whole file and extract the string you need using the reverse of the procedure that you used to insert the string into the binary data and write the file.

For instance, if you used serialization of a class instance then you would re-create the class instance from the file by deserializing and get the string as a property or field of the class instance that was created.

If you wrote a series of binary data items then you would read the same series of data items until you got to the string you wanted.  If you know (or can calculate) the file offset of the string data you can start reading from that offset.

So your starting point for the reading will be the code you used to do the writing.  You need to show that code.


这篇关于如何从二进制写入器写入的数据文件(没有字符串和整数)中读取特定字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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