日期:2014-05-20  浏览次数:20758 次

哪个高手,能把这个C#给弄成VB.NET?下载图用
1,WebRequest和WebResponse

WebRequest request = WebRequest.Create("http://images.cnblogs.com/logo_small.gif"); 
WebResponse response = request.GetResponse(); 
Stream reader = response.GetResponseStream(); 
FileStream writer = new FileStream("x:\\pic.jpg", FileMode.OpenOrCreate, FileAccess.Write);
byte[] buff = new byte[512]; 
int c = 0; //实际读取的字节数 
while ((c=reader.Read(buff, 0, buff.Length)) > 0)
 {  
writer.Write(buff, 0, c); 
}
 writer.Close();
 writer.Dispose(); 
reader.Close();
 reader.Dispose();
 response.Close();


希望给改成VB.NET



------解决方案--------------------
VB.NET code

WebRequest request = WebRequest.Create("http://images.cnblogs.com/logo_small.gif")
Dim response As WebResponse = request.GetResponse()
Dim reader As Stream = response.GetResponseStream()
Dim writer As New FileStream("x:\pic.jpg", FileMode.OpenOrCreate, FileAccess.Write)
Dim buff(511) As Byte
Dim c As Integer = 0 '实际读取的字节数
c=reader.Read(buff, 0, buff.Length)
Do While c > 0
writer.Write(buff, 0, c)
    c=reader.Read(buff, 0, buff.Length)
Loop
 writer.Close()
 writer.Dispose()
reader.Close()
 reader.Dispose()
 response.Close()