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为数量
                        }
                    }
                }
  • 相关阅读:
    20140710 sequence 前缀和
    20140709 testC 数学题
    20140708 testA 组合数学
    20140708 testB DP 组合数学
    Sad :(
    已经是一个废人了……
    Game Theory
    HDU Math Problems
    2-sat问题
    并查集
  • 原文地址:https://www.cnblogs.com/wangjinming/p/3586970.html
Copyright © 2011-2022 走看看