且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从二进制写入器写入的数据文件(没有字符串和整数)中读取特定字符串

更新时间:2023-11-13 17:09:16


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


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


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


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



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.