using System;
using System.IO;
using System.Net;
 
public class CSharpLab
{
    public static void Test()
    {
        string url = "http://blog.darkthread.net/images/darkthreadbanner.gif";
        HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(url);
        HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse();
 
        System.IO.Stream dataStream = httpResponse.GetResponseStream();
        byte[] buffer = new byte[8192];
        
        FileStream fs = new FileStream("X:\\TEMP\\Darkthread.gif", 
            FileMode.Create, FileAccess.Write);
        int size = 0;
        do 
        {
            size = dataStream.Read(buffer, 0, buffer.Length);
            if (size > 0)
                fs.Write(buffer, 0, size);
        } while (size > 0);
        fs.Close();                
 
        httpResponse.Close();
        
        Console.WriteLine("Done at " + DateTime.Now.ToString("HH:mm:ss.fff"));
    }
}

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 狼翔月影 的頭像
    狼翔月影

    狼翔天地

    狼翔月影 發表在 痞客邦 留言(1) 人氣()