BufferedStream.Write 方法
将字节复制到缓冲流,并将缓冲流内的当前位置前进写入的字节数。
**命名空间:**System.IO
**程序集:**mscorlib(在 mscorlib.dll 中)
语法
声明
Public Overrides Sub Write ( _
array As Byte(), _
offset As Integer, _
count As Integer _
)
用法
Dim instance As BufferedStream
Dim array As Byte()
Dim offset As Integer
Dim count As Integer
instance.Write(array, offset, count)
public override void Write (
byte[] array,
int offset,
int count
)
public:
virtual void Write (
array<unsigned char>^ array,
int offset,
int count
) override
public void Write (
byte[] array,
int offset,
int count
)
public override function Write (
array : byte[],
offset : int,
count : int
)
参数
- array
字节数组,从该字节数组将 count 个字节复制到当前缓冲流中。
- offset
缓冲区中的偏移量,从此处开始将字节复制到当前缓冲流中。
- count
要写入当前缓冲流中的字节数。
异常
异常类型 | 条件 |
---|---|
array 的长度减去 offset 小于 count。 |
|
array 为 空引用(在 Visual Basic 中为 Nothing)。 |
|
offset 或 count 为负。 |
|
流关闭或为 空引用(在 Visual Basic 中为 Nothing)。 |
|
流不支持写入。 |
|
在流关闭后调用方法。 |
备注
有关创建文件和向文件中写入文本的示例,请参见 如何:向文件写入文本。有关从文件中读取文本的示例,请参见 如何:从文件读取文本。有关读取和写入二进制文件的示例,请参见 如何:对新建的数据文件进行读取和写入。
示例
此代码示例摘自一个为 BufferedStream 类提供的更大的示例。
' Send the data using the BufferedStream.
Console.WriteLine("Sending data using BufferedStream.")
startTime = DateTime.Now
For i As Integer = 1 To numberOfLoops
bufStream.Write(dataToSend, 0, dataToSend.Length)
Next i
bufStream.Flush()
bufferedTime = DateTime.Now.Subtract(startTime).TotalSeconds
Console.WriteLine("{0} bytes sent In {1} seconds." & vbCrLf, _
numberOfLoops * dataToSend.Length, _
bufferedTime.ToString("F1"))
// Send the data using the BufferedStream.
Console.WriteLine("Sending data using BufferedStream.");
startTime = DateTime.Now;
for(int i = 0; i < numberOfLoops; i++)
{
bufStream.Write(dataToSend, 0, dataToSend.Length);
}
bufStream.Flush();
bufferedTime = (DateTime.Now - startTime).TotalSeconds;
Console.WriteLine("{0} bytes sent in {1} seconds.\n",
numberOfLoops * dataToSend.Length,
bufferedTime.ToString("F1"));
// Send the data using the BufferedStream.
Console::WriteLine( "Sending data using BufferedStream." );
startTime = DateTime::Now;
for ( int i = 0; i < numberOfLoops; i++ )
{
bufStream->Write( dataToSend, 0, dataToSend->Length );
}
bufStream->Flush();
bufferedTime = (DateTime::Now - startTime).TotalSeconds;
Console::WriteLine( "{0} bytes sent in {1} seconds.\n", (numberOfLoops * dataToSend->Length).ToString(), bufferedTime.ToString( "F1" ) );
// Send the data using the BufferedStream.
Console.WriteLine("Sending data using BufferedStream.");
startTime = DateTime.get_Now();
for(int i=0;i < numberOfLoops;i++) {
bufStream.Write(dataToSend, 0, dataToSend.length);
}
bufStream.Flush();
bufferedTime =
((DateTime.get_Now()).Subtract(startTime)).get_TotalSeconds();
Console.WriteLine("{0} bytes sent in {1} seconds.\n",
System.Convert.ToString (numberOfLoops * dataToSend.length),
((System.Double)bufferedTime).ToString("F1"));
平台
Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
请参见
参考
BufferedStream 类
BufferedStream 成员
System.IO 命名空间
CanWrite
Read