我是从事二进制文件工作的菜鸟。它扩展了这个问题:读取数据的“ x”字节
我的二进制文件大小,如果1025 KB,即1049600字节,其中包含1024字节的标头信息。我只想在第1023位(等于1048576 bytes)之后读取剩余数据。
如何排除前1024个字节?
我正在使用相同的代码,但无法正常工作,我的代码有什么问题吗?
Dim arraySizeMinusOne = 5
Dim buffer() As Byte = New Byte(arraySizeMinusOne) {}
Using fs As New FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.None)
fs.Read(buffer, 0, buffer.Length)
Dim _arraySizeMinusOne = 1048575
Dim _buffer() As Byte = New Byte(_arraySizeMinusOne) {}
'Process 1048576 bytes of data here
End Using
创建一个byte
长度为整个文件的数组,减去减去的大小再减去1。最后一个1
原因是vb数组与c#数组不同。在vb中:
Dim buff() As Byte = New Byte(10) {}
在C#中创建一个11大小的数组:
byte[] buff = new byte[10];
创建一个10尺寸!
Using fs As New FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.None)
Dim buff() As Byte = New Byte(CInt(fs.Length - 1024 - 1)) {}
Dim buffTotal() As Byte = New Byte(CInt(fs.Length - 1)) {}
'read all file
fs.Read(buffTotal, 0, buffTotal.Length)
If fs.Length > 1024 Then
'move from 1024 byte to the end to buff array
Buffer.BlockCopy(buffTotal, 1024, buff, 0, buffTotal.Length - 1024)
End If
End Using
buffer
这不是一个好名字,因为在vb中已经存在一个类Buffer
!将其更改为其他内容buff
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句