文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>流下载文件

流下载文件

时间:2011-01-04  来源:共谱一曲

 

                HttpWebResponse wr = (HttpWebResponse)mRequest.GetResponse();

                Stream sIn = wr.GetResponseStream();
                FileStream fs = new FileStream(LocalPath, FileMode.OpenOrCreate, FileAccess.Write);
           //     FileStream f = new FileStream(LocalPath,FileMode.OpenOrCreate,FileAccess.Write);
                long length = wr.ContentLength;
                long i = 0;
                decimal j = 0;

                while (i < length)
                {
                    byte[] buffer = new byte[1024];
                    i += sIn.Read(buffer, 0, buffer.Length);
                    fs.Write(buffer, 0, buffer.Length);

                    if ((i % 1024) == 0)
                    {
                        j = Math.Round(Convert.ToDecimal((Convert.ToDouble(i) / Convert.ToDouble(length)) * 100), 4);
                      //  statusBar1.Text = "当前下载文件大小:" + length.ToString() + "字节   当前下载大小:" + i + "字节 下载进度" + j.ToString() + "%";

                    }
                    else
                    {
                     //   statusBar1.Text = "当前下载文件大小:" + length.ToString() + "字节   当前下载大小:" + i + "字节";
                    }

                }

                sIn.Close();
                wr.Close();
                fs.Close();
                return true;
            }
            catch(Exception ex) { MessageBox.Show(ex.Message); return false; }
        }

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载