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开始放数据

  • 相关阅读:
    制作紧急启动光盘的内容
    开发短信发送程序的几则技巧
    Debugging WOW64
    SOS debug
    决定你高度的——是你对自己的要求(zt)
    Dialog Boxes
    Reference vs. Pointer
    DOCTYPE
    Win32 编程入门
    Assembly binding Configuration Files
  • 原文地址:https://www.cnblogs.com/tao_/p/1972384.html
Copyright © 2011-2022 走看看