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 the 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 the BinaryReader object in c#.
If you observe the above example, we imported a System.IO namespace to access BinaryWriter & BinaryReader objects to create, open and read text from the given file.
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 it as shown below.
This is how you can use the BinaryReader class in c# to read the binary information from a file in the file system.