我必须从二进制文件中读取POD数据并遇到问题。我很可能不知道以提供的方式使用代码。 MyFile长度为1116个字节,包含VB在DOS下编写的propper数据,我可以成功读取它 在显示的示例中,我想在每条记录中读取前65个字节。从65到124的字节在这里并不重要......
Public Structure recStruct
Dim code As Short
<VBFixedString(27)>Dim name As String
<VBFixedString(16)>Dim kat As String
<VBFixedString(16)>Dim bcode As String
Dim price As Single
End Structure
''-------------------------------------------------
Dim REC_SIZE As Integer = 124
Using fs As FileStream = New FileStream(myFile, FileMode.Open, FileAccess.Read)
Dim f As Integer = CInt(fs.Length)
Dim records As Integer = CInt(f / REC_SIZE)
For t As Integer = 1 To records
Dim seekpoint As Integer = (t - 1) * REC_SIZE
'' on second step of loop when t=2
'' program here breaks!
fs.Seek(seekpoint, SeekOrigin.Begin)
Using br As New BinaryReader(fs, New ASCIIEncoding())
Dim s As New recStruct
s.code = br.ReadInt16
s.name = System.Text.Encoding.ASCII.GetString(br.ReadBytes(27))
'' here I would like to skip 32 bytes
'' instead of reading 'kat' and 'bcode' members
s.price = br.ReadSingle
End Using
Next t
End Using
所以我有两个问题 1)当t = 1时,我可以从记录OK中读取数据,但是当t'增加程序中断'fs.Seek(seekpoint,SeekOrigin.Begin)'时。 2)如果不需要,如何跳过所需的字节数,以免丢失读取时间?
如何以预期的方式使这个工作或我在这里做错了什么?