读书人

Stream怎么转为Byte()

发布时间: 2011-12-29 22:09:38 作者: rapoo

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 bytestream.Position =0stream.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 SubEnd 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……

读书人网 >VB Dotnet

热点推荐