zoukankan      html  css  js  c++  java
  • stream的seek方法实例

    using (FileStream outStream = new FileStream(@"D:12.txt", FileMode.Open))
                {
                    using (FileStream fs = new FileStream(@"D:1.txt", FileMode.Open))
                    {
                        //缓冲区太小的话,速度慢而且伤硬盘
                        //声明一个4兆字节缓冲区大小,比如迅雷也有一个缓冲区,如果没有缓冲区的话,
                        //每下载一个字节都要往磁盘进行写,非常伤磁盘,所以,先往内存的缓冲区写字节,当
                        //写够了一定容量之后,再往磁盘进行写操作,减低了磁盘操作。
                        byte[] bytes = new byte[100];
                        int readBytes;
                        //第二个参数Offset表示当前位置的偏移量,一般都传0
                        fs.Seek(100, SeekOrigin.Current);
                        if ((readBytes = fs.Read(bytes, 0, bytes.Length)) > 0) //读取的位置自动往后挪动。
                        {
                            //readBytes为实际读到的byte数,因为最后一次可能不会读满。
                            if (outStream.CanSeek == true)
                                outStream.Seek(100, SeekOrigin.Current);
                                outStream.Write(bytes, 8, readBytes-10);//8为偏移量,10为数量
                        }
                    }
                }
  • 相关阅读:
    java 利用jsoup 爬取知乎首页问题
    ROIAlign, ROIPooling及ROIWarp对比
    yii2.0 gii
    mysql索引操作
    lbs basic mongodb
    php操作mongodb
    设计模式六大原则
    Java集合
    Java 快速失败( fail-fast ) 安全失败( fail-safe )
    计数数组中值的出现次数
  • 原文地址:https://www.cnblogs.com/wangjinming/p/3586970.html
Copyright © 2011-2022 走看看