首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

Stream怎么转为Byte()

2011-12-29 
Stream如何转为Byte()VB.NET codeDim retBytes() As ByteDim weq As System.Net.HttpWebRequestDim wer As

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……

热点排行