本文介绍了BinaryReader计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码应该说的足够多,binaryreader计数是错误的..

代码:

The code should say enough, binaryreader counts wrong..

Code:

Dim objBR As BinaryReader
        Dim objFS As FileStream
        Dim objitem As New item

        objFS = New FileStream(File, FileMode.Open, FileAccess.Read)
        objBR = New BinaryReader(objFS)
        objBR.BaseStream.Seek(0, SeekOrigin.Begin)
        RichTextBox1.Text &= objFS.Position & " - " & objFS.Length & vbCrLf
        While objFS.Position < objFS.Length
            objitem = Nothing
            With objitem
                .strHid1 = objBR.ReadChars(12)
                .value0 = objBR.ReadInt32
                .value1 = objBR.ReadInt32
                .strHid2 = objBR.ReadChars(12)
            End With
            RichTextBox1.Text &=  objFS.Position & vbCrLf
        End While
        objBR.Close()
        objFS.Close()




输出:




Output:

0 - 1612
32
65
97
129
161
193
225
257
289
321
353
386
418
450
482
514
546
578
610
642
674
706
739
771
803
835
867
899
931
963
995
1027
1059
1091
1123
1155
1187
1219
1251
1283
1315
1347
1379
1411
1443
1475
1507
1539
1571
1603



所以他这样算:



So he counts like this:

32
33
32
32
32
32
32
32
32
32
32
33
32
32
32
32
32
32
32
32
32
32
33
32
32
32
32
32
32
32
32
32
32
32
32
32
32
32
32
32
32
32
32
32
32
32
32
32
32
32




任何人都可以解释为什么有33个吗?..


现在,我通过变通方法解决了这个问题,直到我知道是什么原因造成的..




Anyone can explain why that 33 is there?..


For now I fixed it using a work around, until I know what is causing it..

While objFS.Position < objFS.Length
            objitem = Nothing
            Dim tst As Integer = objFS.Position
            objitem.strHid1 = objBR.ReadChars(12)
            objitem.value0 = objBR.ReadInt32
            objitem.value1 = objBR.ReadInt32
            objitem.strHid2 = objBR.ReadChars(12)
            RichTextBox1.Text &= objFS.Position & vbCrLf
            If objFS.Position - tst <> 32 Then
                objFS.Position = tst + 32
            End If
        End While

推荐答案



这篇关于BinaryReader计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-24 13:41