SlideShare a Scribd company logo
1 of 11
BinaryWriter and BinaryReader
Jason
BinaryWriter
 Writes primitive types in binary to a stream and supports writing strings in a
specific encoding.
 BinaryWriter()
 BinaryWriter(Stream)
 BinaryWriter(Stream, Encoding)
 BinaryWriter(Stream, Encoding, Boolean)
BinaryWriter
 Methods
Write(Boolean) Write(Byte) Write(Byte[]) Write(Char)
Write(Char[]) Write(Decimal) Write(Double) Write(Int16)
Write(Int32) Write(Int64) Write(SByte) Write(Single)
Write(String) Write(UInt16) Write(UInt32) Write(UInt64)
Write(Byte[], Int32, Int32) Write(Char[], Int32, Int32)
BinaryReader
 Reads primitive data types as binary values in a specific encoding.
 BinaryReader(Stream)
 BinaryReader(Stream, Encoding)
 BinaryReader(Stream, Encoding, Boolean)
BinaryReader
 Methods
Read() ReadBoolean ReadByte ReadBytes
ReadChar ReadChars ReadDecimal ReadDouble
ReadInt16 ReadInt32 ReadInt64 ReadSByte
ReadSingle ReadString ReadUInt16 ReadUInt32
Read(Char[], Int32, Int32) Read(Byte[], Int32, Int32)
BinaryReader
 example
using (var writer = new BinaryWriter(File.Open(fileName, FileMode.Create)))
{
writer.Write(10);
}
using (var reader = new BinaryReader(File.Open(fileName, FileMode.Open)))
{
reader.ReadInt32();
reader.ReadBytes();
}
reader.ReadInt32()
Answer: 10
reader.ReadBytes()
Answer:
BinaryReader
 example
using (var writer = new BinaryWriter(File.Open(fileName, FileMode.Create)))
{
writer.Write(“Jason”);
}
using (var reader = new BinaryReader(File.Open(fileName, FileMode.Open)))
{
reader.ReadString();
reader.ReadBytes();
}
reader.ReadString()
Answer: Jason
reader.ReadBytes()
Answer:
BinaryWriter and BinaryReader
 example
using (var writer = new BinaryWriter(File.Open(fileName, FileMode.Create)))
{
writer.Write(1.250F);
writer.Write(@"c:Temp");
writer.Write(10);
writer.Write(true);
}
using (var reader = new BinaryReader(File.Open(fileName, FileMode.Open)))
{
var aspectRatio = reader.ReadSingle();
var tempDirectory = reader.ReadString();
var autoSaveTime = reader.ReadInt32();
var showStatusBar = reader.ReadBoolean();
}
BinaryReader
 Remarks
 BinaryReader does not restore the file position after an unsuccessful read.
BinaryReader VS StreamReader
 If the entirety of your data is a straightforward binary encoding of text data,
use StreamReader.
 If you've fundamentally got binary data which may happen to have some
portions in text, use BinaryReader
Reference
 File and Stream I/O
 http://msdn.microsoft.com/en-us/library/k3352a4t(v=vs.110).aspx
 BinaryReader
 http://msdn.microsoft.com/en-us/library/system.io.binaryreader(v=vs.110).aspx
 BinaryWriter
 http://msdn.microsoft.com/en-us/library/gg712841(v=vs.110).aspx

More Related Content

More from LearningTech (20)

vim
vimvim
vim
 
PostCss
PostCssPostCss
PostCss
 
ReactJs
ReactJsReactJs
ReactJs
 
Docker
DockerDocker
Docker
 
Semantic ui
Semantic uiSemantic ui
Semantic ui
 
node.js errors
node.js errorsnode.js errors
node.js errors
 
Process control nodejs
Process control nodejsProcess control nodejs
Process control nodejs
 
Expression tree
Expression treeExpression tree
Expression tree
 
SQL 效能調校
SQL 效能調校SQL 效能調校
SQL 效能調校
 
flexbox report
flexbox reportflexbox report
flexbox report
 
Vic weekly learning_20160504
Vic weekly learning_20160504Vic weekly learning_20160504
Vic weekly learning_20160504
 
Reflection & activator
Reflection & activatorReflection & activator
Reflection & activator
 
Peggy markdown
Peggy markdownPeggy markdown
Peggy markdown
 
Node child process
Node child processNode child process
Node child process
 
20160415ken.lee
20160415ken.lee20160415ken.lee
20160415ken.lee
 
Peggy elasticsearch應用
Peggy elasticsearch應用Peggy elasticsearch應用
Peggy elasticsearch應用
 
Expression tree
Expression treeExpression tree
Expression tree
 
Vic weekly learning_20160325
Vic weekly learning_20160325Vic weekly learning_20160325
Vic weekly learning_20160325
 
D3js learning tips
D3js learning tipsD3js learning tips
D3js learning tips
 
git command
git commandgit command
git command
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 

Binary

  • 2. BinaryWriter  Writes primitive types in binary to a stream and supports writing strings in a specific encoding.  BinaryWriter()  BinaryWriter(Stream)  BinaryWriter(Stream, Encoding)  BinaryWriter(Stream, Encoding, Boolean)
  • 3. BinaryWriter  Methods Write(Boolean) Write(Byte) Write(Byte[]) Write(Char) Write(Char[]) Write(Decimal) Write(Double) Write(Int16) Write(Int32) Write(Int64) Write(SByte) Write(Single) Write(String) Write(UInt16) Write(UInt32) Write(UInt64) Write(Byte[], Int32, Int32) Write(Char[], Int32, Int32)
  • 4. BinaryReader  Reads primitive data types as binary values in a specific encoding.  BinaryReader(Stream)  BinaryReader(Stream, Encoding)  BinaryReader(Stream, Encoding, Boolean)
  • 5. BinaryReader  Methods Read() ReadBoolean ReadByte ReadBytes ReadChar ReadChars ReadDecimal ReadDouble ReadInt16 ReadInt32 ReadInt64 ReadSByte ReadSingle ReadString ReadUInt16 ReadUInt32 Read(Char[], Int32, Int32) Read(Byte[], Int32, Int32)
  • 6. BinaryReader  example using (var writer = new BinaryWriter(File.Open(fileName, FileMode.Create))) { writer.Write(10); } using (var reader = new BinaryReader(File.Open(fileName, FileMode.Open))) { reader.ReadInt32(); reader.ReadBytes(); } reader.ReadInt32() Answer: 10 reader.ReadBytes() Answer:
  • 7. BinaryReader  example using (var writer = new BinaryWriter(File.Open(fileName, FileMode.Create))) { writer.Write(“Jason”); } using (var reader = new BinaryReader(File.Open(fileName, FileMode.Open))) { reader.ReadString(); reader.ReadBytes(); } reader.ReadString() Answer: Jason reader.ReadBytes() Answer:
  • 8. BinaryWriter and BinaryReader  example using (var writer = new BinaryWriter(File.Open(fileName, FileMode.Create))) { writer.Write(1.250F); writer.Write(@"c:Temp"); writer.Write(10); writer.Write(true); } using (var reader = new BinaryReader(File.Open(fileName, FileMode.Open))) { var aspectRatio = reader.ReadSingle(); var tempDirectory = reader.ReadString(); var autoSaveTime = reader.ReadInt32(); var showStatusBar = reader.ReadBoolean(); }
  • 9. BinaryReader  Remarks  BinaryReader does not restore the file position after an unsuccessful read.
  • 10. BinaryReader VS StreamReader  If the entirety of your data is a straightforward binary encoding of text data, use StreamReader.  If you've fundamentally got binary data which may happen to have some portions in text, use BinaryReader
  • 11. Reference  File and Stream I/O  http://msdn.microsoft.com/en-us/library/k3352a4t(v=vs.110).aspx  BinaryReader  http://msdn.microsoft.com/en-us/library/system.io.binaryreader(v=vs.110).aspx  BinaryWriter  http://msdn.microsoft.com/en-us/library/gg712841(v=vs.110).aspx