SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Mehr von LearningTech

Mehr von 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
 

Kürzlich hochgeladen

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 

Kürzlich hochgeladen (20)

DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 

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