• Stream.Read() / Stream.Position


    public int Read(byte[] buffer, int offset, int count):

    buffer-存放数据的数组;

    offset-从buffer的那一位开始存放数据,offset需满足 0 < offset < buffer.Lenght-1;

    count-读入buffer中数据的长度,count需要满足 0 < count < buffer.Lenght-offset;

    eg:

    System.IO.StreamReader sr =
                    new System.IO.StreamReader("d:\\pathtest.txt");
                System.IO.Stream st = sr.BaseStream;
                byte[] bts = new byte[1025];
                int count =
                    st.Read(bts, 3, bts.Length-3);

                int pos =(int)st.Position;

                st.Position = 5;

                while (count > 0)
                { 
                    count = st.Read(bts, 3, bts.Length-3);
                }

     byte[] bts = new byte[1025];
     st.Read(bts, 0, bts.Length);

     byte[] bts = new byte[1025];
    st.Read(bts, 3, bts.Length-3);//从字节数组bts2的第3+1开始放数据

     

    byte[] bts = new byte[1025];
    st.Position = 5;//设置指针为当前流的第5位置

    st.Read(bts, 3, bts.Length-3); //从当前流的第6位置开s始读取,并从字节数组bts2的第3+1开始放数据

  • 相关阅读:
    清理yum源
    XZ压缩
    Linux命令之dot
    calltree查看工程代码中的函数调用关系
    valgrind 打印程序调用树+进行多线程性能分析
    LINUX 性能 测试 优化工具
    TCP/IP(84) 详解
    perf---LINUX内核研究
    廖雪锋笔记3:类型转换
    廖雪锋笔记2:list,tuble
  • 原文地址:https://www.cnblogs.com/tao_/p/1972384.html
Copyright © 2020-2023  润新知