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

C# 读取网络txt资料 并写在本地txt文件中

2013-09-28 
C# 读取网络txt文件 并写在本地txt文件中public void WriteStream(){try{stirng ImagesPath ImagesPath

C# 读取网络txt文件 并写在本地txt文件中

public void WriteStream()        {            try            {               stirng ImagesPath = ImagesPath + "\\2013-09-27.txt";                HttpWebRequest oHttp_Web_Req = (HttpWebRequest)WebRequest.Create("http://tuitui.uzai.com/baiduBosom/index.20130927.txt");                Stream oStream = oHttp_Web_Req.GetResponse().GetResponseStream();                using (StreamReader respStreamReader = new StreamReader(oStream, Encoding.UTF8))                {                    string line = string.Empty;                    while ((line = respStreamReader.ReadLine()) != null)                    {                                                        UTF8Encoding utf8 = new UTF8Encoding(false);                                //写txt文件                                using (StreamWriter sw = new StreamWriter(ImagesPath, true, utf8))                                {                                                                      sw.WriteLine(line);                                }                    }                }            }            catch (Exception ex)            {            }        }

热点排行