专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > VB Dotnet

Stream怎么转为Byte()

发布时间:2011-06-23 16:02:36 文章来源:www.iduyao.cn 采编人员:星星草
Stream如何转为Byte()
VB.NET code

Dim retBytes() As Byte

        Dim weq As System.Net.HttpWebRequest 
        Dim wer As System.Net.HttpWebResponse
        Dim stream As System.IO.Stream
        Dim ms As New System.IO.MemoryStream
        Try

            weq = CType(System.Net.WebRequest.Create(sPath), System.Net.HttpWebRequest)
            wer = CType(weq.GetResponse(), System.Net.HttpWebResponse)
            stream = wer.GetResponseStream()

            '''现在这个stream如何转为byte
            '''retBytes=??????

        Catch ex As Exception
            Dim err As String = ex.Message
        Finally
            ms.Close()
            wer.Close()

        End Try





------解决方案--------------------
方法一:
VB.NET code
dim bytdata(stream.Length) as byte
stream.Position =0
stream.Read(bytedata,0,stream.Length)

------解决方案--------------------
VB.NET code
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim retBytes() As Byte
        Dim sPath As String = "http://www.baidu.com"
        Dim weq As System.Net.HttpWebRequest
        Dim wer As System.Net.HttpWebResponse
        Dim stream As System.IO.BinaryReader
        'Dim ms As New System.IO.MemoryStream
        Try

            weq = CType(System.Net.WebRequest.Create(sPath), System.Net.HttpWebRequest)
            wer = CType(weq.GetResponse(), System.Net.HttpWebResponse)
            stream = New IO.BinaryReader(wer.GetResponseStream())

            ReDim retBytes(wer.ContentLength - 1)
            stream.Read(retBytes, 0, wer.ContentLength)
            '''现在这个stream如何转为byte
            '''retBytes=??????

        Catch ex As Exception
            Dim err As String = ex.Message
        Finally
            'ms.Close()
            stream.Close()
            wer.Close()

        End Try


    End Sub
End Class

------解决方案--------------------
忘了减1了
dim bytdata(stream.Length-1) as byte
不好意思,不太习惯
探讨
不行啊,stream.Length这里出错。


引用:

方法一:
VB.NET code
dim bytdata(stream.Length) as byte
stream.Position =0
stream.Read(bytedata,0,stream.Length)


方法二
内存流可以直接stream.ToAr……
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: