Create FileStream class with the specified path and creation mode.
using System;
using System.IO;
class FStream
{
static void Main()
{
const string fileName = "data.dat";
byte[] dataArray = new byte[100000];
new Random().NextBytes(dataArray);
using(FileStream fileStream = new FileStream(fileName, FileMode.Create))
{
for(int i = 0; i < dataArray.Length; i++)
{
fileStream.WriteByte(dataArray[i]);
}
fileStream.Seek(0, SeekOrigin.Begin);
for(int i = 0; i < fileStream.Length; i++)
{
if(dataArray[i] != fileStream.ReadByte())
{
Console.WriteLine("Error writing data.");
return;
}
}
Console.WriteLine(fileStream.Name);
}
}
}
Related examples in the same category