使用FileStream读取文件后,在用BinaryReader读取文件流开头为 00 07 00 05 ……
使用BinaryReader.ReadUInt16 读取出来是 07 00 变成了 256 * 7 而我实际上只想得到 7(4个字节一组)。
另外在文件较大的时候,对二进制流进行循环,大约60M的数据,循环一次需要近11秒,这个显然太慢了,希望在1秒作用。
有没有办法快速查找到某字节或者分块循环。(我不知道需要的字节在哪里,而且因为整个流是连续不断,每个块的结束就是另一个快的开始,所以分割会不会出现错误?)
代码如下,不涉及其它代码
Dim dtm As Date = Date.now
Dim strFilePath As String = ""
Dim fs As New System.IO.FileStream(strFilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read)
Dim br As New System.IO.BinaryReader(fs)
Dim nFS As Integer = fs.length
Dim n As Integer = 0
Do While n<fs.length
If nfs -n >= 4 Then
Dim nlength As Integer = br.readbyte * 256 + br.readbyte
Dim nString As Integer = br.readbyte * 256 + br.readbyte
Select Case nlength
Case 0
n = n + 4
Case 1,2,3,4
n = n + nlength
Case Else
br.readbytes(nLength-4)
n = n + nlength
End Select
Else
n = fs.length
End If
Loop
Output.Show((Date.now - dtm).Totalseconds)