VB.Net读取资源二进制文件

时间:2015-03-26 02:45:06

标签: vb.net

我有一个名为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二进制文件?

2 个答案:

答案 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.StoreCodebyte[]因为您需要将其复制到MemoryStream对象,然后使用BinaryReader来阅读流的内容

Using ms As New MemoryStream(My.Resources.StoreCode)
    Using readBinaryFile As New BinaryReader(ms)
        'read operations
    End Using
End Using

我希望它有所帮助。