Stream::Read 方法 (array<Byte>^, Int32, Int32)
来源:互联网 发布:临沂淘宝代运营 编辑:程序博客网 时间:2024/05/21 00:52
Stream::Read 方法 (array<Byte>^, Int32, Int32)
.NET Framework (current version)
其他版本
当在派生类中重写时,从当前流读取字节序列,并将此流中的位置提升读取的字节数。
程序集: mscorlib(mscorlib.dll 中)
语法
C#
C++
F#
VB
public:virtual int Read(array<unsigned char>^ buffer,int offset,int count) abstract
参数
- buffer
字节数组。此方法返回时,该缓冲区包含指定的字符数组,该数组的 offset 和 (offset + count -1) 之间的值由从当前源中读取的字节替换。
- offset
buffer 中的从零开始的字节偏移量,从此处开始存储从当前流中读取的数据。
- count
要从当前流中最多读取的字节数。
返回值
Type: System::Int32读入缓冲区中的总字节数。如果很多字节当前不可用,则总字节数可能小于请求的字节数;如果已到达流结尾,则为零 (0)。
异常
offset 与 count 的和大于缓冲区长度。
buffer 为 null。
offset 或 count 为负。
发生 I/O 错误。
流不支持读取。
在流关闭后调用方法。
备注
使用 CanRead 属性来确定当前实例是否支持读取。使用 ReadAsync 方法以从当前流中以异步方式读取。
此方法的实现读取的最多 count 从当前的字节流,并将其在存储 buffer 开始的位置 offset。流中的当前位置高级读取 ; 的字节数但是,如果发生异常,该流中的当前位置保持不变。实现返回读取的字节数。该实现将阻止直到至少一个字节的数据可供读取的事件中任何数据都可用。 Read只有当在流中没有更多数据,并且没有更多预期 (如套接字已关闭或文件结尾),则返回 0。实现可以自由地返回少于所请求的字节,即使尚未达到流的末尾。
使用 BinaryReader 用于读取基元数据类型。
示例
下面的示例演示如何使用 Read 要读取的数据块。
C#
C++
VB
using namespace System;using namespace System::IO;public ref class Block{public: static void Main() { Stream^ s = gcnew MemoryStream(); for (int i = 0; i < 100; i++) { s->WriteByte((Byte)i); } s->Position = 0; // Now read s into a byte buffer. array<Byte>^ bytes = gcnew array<Byte>(s->Length); int numBytesToRead = (int) s->Length; int numBytesRead = 0; while (numBytesToRead > 0) { // Read may return anything from 0 to 10. int n = s->Read(bytes, numBytesRead, 10); // The end of the file is reached. if (n == 0) { break; } numBytesRead += n; numBytesToRead -= n; } s->Close(); // numBytesToRead should be 0 now, and numBytesRead should // equal 100. Console::WriteLine("number of bytes read: {0:d}", numBytesRead); }};int main(){ Block::Main();}
版本信息
Universal Windows Platform
4.5 后可用
.NET Framework
1.1 后可用
Portable Class Library
受以下版本支持:portable .NET platforms
Silverlight
2.0 后可用
Windows Phone Silverlight
7.0 后可用
Windows Phone
8.1 后可用
4.5 后可用
.NET Framework
1.1 后可用
Portable Class Library
受以下版本支持:portable .NET platforms
Silverlight
2.0 后可用
Windows Phone Silverlight
7.0 后可用
Windows Phone
8.1 后可用
0 0
- Stream::Read 方法 (array<Byte>^, Int32, Int32)
- Stream::Read 方法 (array<Byte>^, Int32, Int32)
- String.Substring 方法 (Int32, Int32)
- GraphicsPath.AddArc 方法 (Int32, Int32, Int32, Int32, Single, Single)
- convert byte[4] to int32
- Point.Offset 方法 (Int32, Int32) &&Point.Offset 方法 (Point)
- Int32.TryParse (String, Int32)
- C#中Socket.Receive 方法 (Byte[], Int32, SocketFlags)的SocketFlags的含义
- VB String.Split 方法 (String[], Int32, StringSplitOptions)
- C#Stream、BaseStream、StreamReader、BinaryReader、Convert.ToInt32、int32.Parse()
- LINQ to Entities 不识别方法“Int32 ToInt32(System.String) 或 “Int32 Parse(System.String)”
- TreeView插入节点的方法:TreeNodeCollection.Insert 方法 (Int32, TreeNode)
- C# int32与byte[] 互转 / C/C++ int与BYTE[]互转
- 使用Int32.parse()方法要保证输入参数的正确性
- C#:对Int32数据类型直接增加位测试扩展方法
- LINQ to Entities 不识别方法“Int32 ToInt32(System.String)
- Int32.Parse(string)
- 数值转换(Convert/Int32)
- CSS单/多行文本溢出部分显示省略号
- pkg-config 详解
- 代码规范
- 身份证号码验证算法
- Maven 环境的配置
- Stream::Read 方法 (array<Byte>^, Int32, Int32)
- 3.多线程代价
- centos 开通防火墙端口权限
- Spring Boot ---- 快速开发web应用的神器
- Spark定制班第27课:Spark Streaming的为什么在DStream的Action操作之外也可能产生Job操作
- 每天一个命令(17)vmstat - Report virtual memory statistics
- 基于Dex分包方案---热修复、热更新、插件化
- 集合CollectionUtils的操作方法
- LeakCanary: 让内存泄露无所遁形