zoukankan      html  css  js  c++  java
  • 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开始放数据

  • 相关阅读:
    EF框架开发后台错误问题集合
    如何实践MVP+RxJava+Retrofit(1)
    Android的FixScrollView自定义控件
    那些React-Native踩过的的坑
    P3105 [USACO14OPEN]公平的摄影Fair Photography
    模板合集
    关于最近情况的说明
    落谷P3941 入阵曲
    51nod 1952 栈
    BZOJ 2298: [HAOI2011]problem a
  • 原文地址:https://www.cnblogs.com/tao_/p/1972384.html
Copyright © 2011-2022 走看看