我有一个名为StoreCode
的资源,我似乎无法使用以下方式读取该文件:
Dim readBinaryFile As BinaryReader
readBinaryFile = New BinaryReader(My.Resources.StoreCode)
有一个错误:
Value of type:'1-dimensional array of Byte' cannot be converted to 'System.IO.Stream'
如何正确read
二进制文件?
答案 0 :(得分:1)
My.Resources.StoreCode
可能是一个字节数组。相反,它需要是一个文件流,类似于:
Dim readBinaryFile As BinaryReader
Dim fs As System.IO.Stream = File.Open(pathstring, FileMode.Open)
readBinaryFile = New BinaryReader(fs)
答案 1 :(得分:1)
似乎My.Resources.StoreCode
是byte[]
因为您需要将其复制到MemoryStream
对象,然后使用BinaryReader
来阅读流的内容
Using ms As New MemoryStream(My.Resources.StoreCode)
Using readBinaryFile As New BinaryReader(ms)
'read operations
End Using
End Using
我希望它有所帮助。