CSharp.Net-Informations.com
   Home      .Net Framework      VB.NET      C#                                                                      About


  How to use C# BinaryReader Class

C# BinaryReader Object works at lower level of Streams. C# BinaryReader is using for read primitive types as binary values in a specific encoding stream. Binaryreader Object works with Stream Objects that provide access to the underlying bytes. For creating a BinaryReader Object , you have to first create a FileStream Object and then pass BinaryReader to the constructor method .

  FileStream readStream ;
  readStream = new FileStream("c:\\testBinary.dat", FileMode.Open);

BinaryReader readBinary = new BinaryReader(readStream);

The main advantages of Binary information is that stores files as Binary format is the best practice of space utilization.

         C# Source Code Download           Print Source Code
         How to use C# BinaryReader Class - Download
        
C# Tutorial

using System;
using System.Windows.Forms;
using System.IO;
using System.Text;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            FileStream readStream ;
            string msg = null;
            try
            {
                readStream = new FileStream("c:\\csharp.net-informations.dat", FileMode.Open);
                BinaryReader readBinary = new BinaryReader(readStream);
                msg = readBinary.ReadString();
                MessageBox.Show(msg);
                readStream.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show (ex.ToString());
            }
        }
    }
}

BinaryWriter you can use in the same way to write as binary.

CSharp File (I/O) Operations Related Contents
*     How to use C# Directory Class
*     How to use C# File Class
*     How to use C# FileStream Class
*     How to use C# Textreader Class
*     A simple C# Text Reader source code
*     How to use C# TextWriter Class
*     How to use C# BinaryWriter Class


   Home      VB.NET      C#
CSharp Related Topics
*     An overview of Microsoft CSharp
*     C# Language Tutorial
*     C# Statements Tutorial
*     C# Collection Tutorial
*     C# String Tutorial
*     C# File Operations Tutorial
*     C# Excel Tutorial
*     C# Crystal Reports Tutorial
*     CSharp Communication Tutorial
*     C# Ado.Net Tutorial and Source Code
*     C# ADO.NET data Providers Tutorial
*     C# Dataset Tutorial
*     C# DataAdapater Tutorial
*     Csharp DataView Tutorial
*     Csharp Remoting Tutorial
*     C# XML Tutorial
*     C# DataGridView Tutorial
   Home      VB.NET      C#
More Source Code :   
Mail to :  feedback@net-informations.com
  |  Home   |  VB.NET   |  C#   |  SiteMap   |  Terms of Use   |  About   |
net-informations.com (C) 2010
All Rights Reserved. All other trademarks are property of their respective owners.