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

posted on 2011-03-06 17:31  大松  阅读(486)  评论(0编辑  收藏  举报