C# BinaryWriter Write(Byte[], Int32, Int32)
Description
BinaryWriter Write(Byte[], Int32, Int32)
Writes a region
of a byte array to the current stream.
Syntax
BinaryWriter.Write(Byte[], Int32, Int32)
has the following syntax.
public virtual void Write(
byte[] buffer,//from ww w . jav a2 s .c o m
int index,
int count
)
Parameters
BinaryWriter.Write(Byte[], Int32, Int32)
has the following parameters.
buffer
- A byte array containing the data to write.index
- The starting point in buffer at which to begin writing.count
- The number of bytes to write.
Returns
BinaryWriter.Write(Byte[], Int32, Int32)
method returns
Example
using System;// w w w . j a v a2 s. c o m
using System.IO;
class ConsoleApplication
{
const string fileName = "data.dat";
static void Main()
{
using (BinaryWriter writer = new BinaryWriter(File.Open(fileName, FileMode.Create)))
{
byte[] bytes = new byte[]{1,2,3,4};
writer.Write(bytes,0,2);
}
using (BinaryReader reader = new BinaryReader(File.Open(fileName, FileMode.Open)))
{
Console.WriteLine(reader.ReadInt32());
}
}
}