zoukankan      html  css  js  c++  java
  • 断点续传,下载。

                private long tempStartPostion = 0; //开始位置
                FileStream fs;
                if (File.Exists("D://test.zip"))
                {
                    fs = System.IO.File.OpenWrite("D://test.zip");
                    tempStartPostion = fs.Length;// 文件流现在的大小
                    fs.Seek(tempStartPostion, System.IO.SeekOrigin.Current); //从开始位置移动到文件流中的当前位置
                }
                else
                {
                    fs = new System.IO.FileStream("D://test.zip", System.IO.FileMode.Create);
                    tempStartPostion = 0;
                }
                Uri uri = new Uri("http://+路径");//http://www.cnblogs.com/wangliuzheng/
                HttpWebRequest hwr = (HttpWebRequest)HttpWebRequest.Create(uri);
                if (tempStartPostion > 0)
                {
                    hwr.AddRange((int)tempStartPostion);
                }
                HttpWebResponse hwrs = (HttpWebResponse)hwr.GetResponse();
                long totalBytes = hwrs.ContentLength;
                Stream st = hwrs.GetResponseStream();
                byte[] bt = new byte[1024];
                int size = st.Read(bt, 0, (int)bt.Length);
                while (size > 0)
                {
                    Application.DoEvents();
                    fs.Write(bt, 0, size);
                    size = st.Read(bt, 0, bt.Length);
                }
                fs.Close();
                st.Close();
        }
    wangliuzheng1990@126.com
  • 相关阅读:
    异常处理学习笔记
    android 测试
    android 创建快捷方式
    POJ 3320 尺取法(基础题)
    HDOJ 1260 DP
    数位DP练习
    P2727 Stringsobits
    poj 2229 DP
    Canada Cup 2016 C. Hidden Word
    hdoj 1231 最大连续子列和
  • 原文地址:https://www.cnblogs.com/wangliuzheng/p/3007539.html
Copyright © 2011-2022 走看看