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 (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

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Kürzlich hochgeladen (20)

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 

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