- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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# BinaryWriter class?
If you want to write binary information into the stream, then use the BinaryWriter class in C#. You can find it under the System.IO namespace.
The following is the implementation of the BinaryWriter class −
static void WriteMe() { using (BinaryWriter w = new BinaryWriter(File.Open("C:\abc.txt", FileMode.Create))) { w.Write(37.8); w.Write("test”); } } 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()); } }
Above, theBinaryWriter class opens a file and writes content into it −
static void WriteMe() { using (BinaryWriter w = new BinaryWriter(File.Open("C:\abc.txt", FileMode.Create))) { w.Write(37.8); w.Write("test"); } }
Advertisements