In c#, BinaryReader is a class of System.IO namespace and it is useful to read binary information from the stream with a particular encoding. By default, the BinaryReader will use UTF-8 Encoding unless we specify other encodings.
Now, we will see how to use BinaryReader class in c# to read binary information from the file with examples.
Following is the example of writing a text to the file in binary format and retrieving that binary information from the file using BinaryReader object in c#.
static void Main(string args)
string fpath = @"D:\Test.txt";
// Writing values to file
using (BinaryWriter bw = new BinaryWriter(File.Open(fpath, FileMode.Create)))
bw.Write("Welcome to Tutlane");
// Reading Values by creating BinaryReader instance
using (BinaryReader br = new BinaryReader(File.Open(fpath, FileMode.Open)))
When we execute the above example, it will create a “Test.txt” file in D drive and read a text from the created file and return the result like as shown below.
This is how we can use BinaryReader class in c# to read the binary information from a file in the file system.