zoukankan      html  css  js  c++  java
  • stream的Read、Write方法实例

    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为数量
                        }
                    }
                }

  • 相关阅读:
    DRF中的序列化器
    Django REST framework的分页
    DRF的解析器和渲染器
    DRF 权限 频率
    Django ContentType组件
    CORS跨域请求
    RESTful API介绍
    module.exports 和 exports(转)
    vue全选反选demo
    wangEditor大图片上传问题
  • 原文地址:https://www.cnblogs.com/dongyl/p/3595582.html
Copyright © 2011-2022 走看看