Write byte array to a file with buffered stream in CSharp

Description

The following code shows how to write byte array to a file with buffered stream.

Example


//from   ww  w .  j av a  2 s. c  o m
using System;
using System.IO;

public class MainClass
{
    public static int Main(string[] args)
    {

    FileStream dumpFile = new FileStream("Dump.dat", FileMode.Create, FileAccess.ReadWrite);
    BufferedStream myFileBuffer = new BufferedStream(dumpFile);
    
    byte[] str = {127, 0x77, 0x4, 0x0, 0x0, 0x16};
    myFileBuffer.Write(str, 0, str.Length);

    // add changes to file.
    myFileBuffer.Close();  // Flushes.
    dumpFile.Close();  // Flushes.

    return 0;
    }
}




















Home »
  C# Tutorial »
    IO »




File Attribute
File Security
Directory Attribute
Directory Recursive
Binary File
Text Field
Buffered IO
Create Copy Delete Move
CSV
Drive
File System Watcher
Isolated Storage
MemoryStream
Serialize
Zip