- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to use C# BinaryReader class?
Use the BinaryReader class if you want to read binary information from the stream.
The BinaryReader class is in System.IO namespace.
The following is an example showing using the BinaryReader class to read from a file −
static void WriteMe() { using (BinaryWriter w = new BinaryWriter(File.Open("C:\abc.txt", FileMode.Create))) { w.Write(25.9); w.Write("DEMO DATA"); } } static void ReadMe() { using (BinaryReader r = new BinaryReader(File.Open("C:\abc.txt", FileMode.Open))) { Console.WriteLine("Value : " + r.ReadDouble()); Console.WriteLine("Value : " + r.ReadString()); } }
The above method is called in the Main() method −
static void Main(string[] args) { WriteMe(); ReadMe(); Console.ReadKey(); }
- Related Articles
- How to use C# BinaryWriter class?
- How to use C# FileStream class?
- How to use Stack class in C#?
- How to use Queue class in C#?
- How to use ArrayList class in C#?
- How to use NameValueCollection class in C#?
- How to use the directory class in C#?
- How to use WriteLine() method of Console class in C#?
- How to use ReadKey() method of Console class in C#?
- How to use the Clear method of array class in C#?
- How to use the Clone() method of array class in C#?
- How to use the Copy(, ,) method of array class in C#
- How to use the CopyTo(,) method of array class in C#
- How to use the GetLength method of array class in C#?
- How to use the GetLongLength method of array class in C#?

Advertisements