Reading and Writing Data – C# – part 1 (Binary Files)

Binary Files

Most important methods:

  • Read(), Write(), BeginRead(), BeginWrite(), Flush()
Stream inputStream = File.OpenRead(@"C:\test\someFile.cs");
Stream outputStream = File.OpenWrite(@"C:\test\someOtherFile.cs");

byte[] buffer = new Byte[SizeBuff];
int bytesRead;

while ( (bytesRead = inputStream.Read(buffer,0,SIZE_BUFF)) > 0 )
{
   outputStream.Write(buffer,0,bytesRead);
}

inputStream.Close()
outputStream.Close()

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s