using System;
using System.IO;
using System.Text;
using System.Security.AccessControl;
class FileStreamExample
{
public static void Main()
{
try
{
byte[] messageByte = Encoding.ASCII.GetBytes("Here is some data.");
FileStream fWrite = new FileStream("test.txt", FileMode.Create, FileAccess.ReadWrite, FileShare.None, 8, FileOptions.None);
fWrite.WriteByte((byte)messageByte.Length);
fWrite.Write(messageByte, 0, messageByte.Length);
fWrite.Close();
FileStream fRead = new FileStream("test.txt", FileMode.Open);
int length = (int)fRead.ReadByte();
byte[] readBytes = new byte[length];
fRead.Read(readBytes, 0, readBytes.Length);
fRead.Close();
Console.WriteLine(Encoding.ASCII.GetString(readBytes));
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
}