<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FCSharp_Tutorial%2FFile_Directory_Stream%2FBinaryReader</id>
		<title>Csharp/CSharp Tutorial/File Directory Stream/BinaryReader - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FCSharp_Tutorial%2FFile_Directory_Stream%2FBinaryReader"/>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/File_Directory_Stream/BinaryReader&amp;action=history"/>
		<updated>2026-04-29T15:02:16Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/File_Directory_Stream/BinaryReader&amp;diff=6780&amp;oldid=prev</id>
		<title> в 15:31, 26 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/File_Directory_Stream/BinaryReader&amp;diff=6780&amp;oldid=prev"/>
				<updated>2010-05-26T15:31:53Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 15:31, 26 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/File_Directory_Stream/BinaryReader&amp;diff=6781&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/File_Directory_Stream/BinaryReader&amp;diff=6781&amp;oldid=prev"/>
				<updated>2010-05-26T12:20:25Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==BinaryReader==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;C# defines two binary stream classes that can be used to read and write binary data directly.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;OL&amp;gt;&amp;lt;LI&amp;gt;BinaryReader.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;BinaryWriter.&amp;lt;/LI&amp;gt;&amp;lt;/OL&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;A BinaryReader is a wrapper around a byte stream that handles the reading of binary data.&amp;lt;/p&amp;gt;&lt;br /&gt;
Method&lt;br /&gt;
Description&lt;br /&gt;
int Read()&lt;br /&gt;
Returns an integer representation of the next available character. Returns -1 when the end of the file is encountered.&lt;br /&gt;
int Read(byte[ ] buf, int offset, int num)&lt;br /&gt;
Attempts to read up to num bytes into buf starting at buf[offset], returning the number of bytes successfully read.&lt;br /&gt;
int Read(char[ ] buf, int offset, int num)&lt;br /&gt;
Attempts to read up to num characters into buf starting at buf[offset], returning the number of characters successfully read.&lt;br /&gt;
&amp;lt;p&amp;gt;Commonly Used Input Methods Defined by BinaryReader&amp;lt;/p&amp;gt;&lt;br /&gt;
Method&lt;br /&gt;
Description&lt;br /&gt;
bool ReadBoolean()&lt;br /&gt;
Reads a bool.&lt;br /&gt;
byte ReadByte()&lt;br /&gt;
Reads a byte.&lt;br /&gt;
sbyte ReadSByte()&lt;br /&gt;
Reads an sbyte&lt;br /&gt;
byte[] ReadBytes(int num)&lt;br /&gt;
Reads num bytes and returns them as an array.&lt;br /&gt;
char ReadChar()&lt;br /&gt;
Reads a char.&lt;br /&gt;
char[] ReadChar(int num)&lt;br /&gt;
Reads num characteds and returns them as an array&lt;br /&gt;
double ReadDouble()&lt;br /&gt;
Reads a double&lt;br /&gt;
float ReadSingle()&lt;br /&gt;
Reads a float&lt;br /&gt;
short ReadInt16()&lt;br /&gt;
Reads a short&lt;br /&gt;
int ReadInt32()&lt;br /&gt;
Reads an int&lt;br /&gt;
long ReadInt64()&lt;br /&gt;
Reads a long&lt;br /&gt;
ushort ReadUInt16()&lt;br /&gt;
Reads a ushort&lt;br /&gt;
uint ReadUInt32()&lt;br /&gt;
Reads a uint&lt;br /&gt;
ulong ReadUInt64()&lt;br /&gt;
Reads a ulong&lt;br /&gt;
string ReadString()&lt;br /&gt;
Reads a string that has been written using a BinaryWriter.&lt;br /&gt;
&lt;br /&gt;
==Read decimal, strings and char from a binary file using the BinaryReader==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
static class MainClass&lt;br /&gt;
{&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        // Create a new file and writer.&lt;br /&gt;
        using (FileStream fs = new FileStream(&amp;quot;test.bin&amp;quot;, FileMode.Create))&lt;br /&gt;
        {&lt;br /&gt;
            using (BinaryWriter w = new BinaryWriter(fs))&lt;br /&gt;
            {&lt;br /&gt;
                // Write a decimal, two strings, and a char.&lt;br /&gt;
                w.Write(124.23M);&lt;br /&gt;
                w.Write(&amp;quot;Test string&amp;quot;);&lt;br /&gt;
                w.Write(&amp;quot;Test string 2&amp;quot;);&lt;br /&gt;
                w.Write(&amp;quot;!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        using (FileStream fs = new FileStream(&amp;quot;test.bin&amp;quot;, FileMode.Open))&lt;br /&gt;
        {&lt;br /&gt;
            using (StreamReader sr = new StreamReader(fs))&lt;br /&gt;
            {&lt;br /&gt;
                // Read the data and convert it to the appropriate data type.&lt;br /&gt;
                fs.Position = 0;&lt;br /&gt;
                using (BinaryReader br = new BinaryReader(fs))&lt;br /&gt;
                {&lt;br /&gt;
                    Console.WriteLine(br.ReadDecimal());&lt;br /&gt;
                    Console.WriteLine(br.ReadString());&lt;br /&gt;
                    Console.WriteLine(br.ReadString());&lt;br /&gt;
                    Console.WriteLine(br.ReadChar());&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;124.23&lt;br /&gt;
Test string&lt;br /&gt;
Test string 2&lt;br /&gt;
!&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reset the file pointer to the start==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
static class MainClass&lt;br /&gt;
{&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        // Create a new file and writer.&lt;br /&gt;
        using (FileStream fs = new FileStream(&amp;quot;test.bin&amp;quot;, FileMode.Create))&lt;br /&gt;
        {&lt;br /&gt;
            using (BinaryWriter w = new BinaryWriter(fs))&lt;br /&gt;
            {&lt;br /&gt;
                // Write a decimal, two strings, and a char.&lt;br /&gt;
                w.Write(124.23M);&lt;br /&gt;
                w.Write(&amp;quot;Test string&amp;quot;);&lt;br /&gt;
                w.Write(&amp;quot;Test string 2&amp;quot;);&lt;br /&gt;
                w.Write(&amp;quot;!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        using (FileStream fs = new FileStream(&amp;quot;test.bin&amp;quot;, FileMode.Open))&lt;br /&gt;
        {&lt;br /&gt;
            using (StreamReader sr = new StreamReader(fs))&lt;br /&gt;
            {&lt;br /&gt;
                using (BinaryReader br = new BinaryReader(fs))&lt;br /&gt;
                {&lt;br /&gt;
                    Console.WriteLine(br.ReadDecimal());&lt;br /&gt;
                    Console.WriteLine(br.ReadString());&lt;br /&gt;
                    Console.WriteLine(br.ReadString());&lt;br /&gt;
                    Console.WriteLine(br.ReadChar());&lt;br /&gt;
                }&lt;br /&gt;
                // Read the data and convert it to the appropriate data type.&lt;br /&gt;
                fs.Position = 0;&lt;br /&gt;
                using (BinaryReader br = new BinaryReader(fs))&lt;br /&gt;
                {&lt;br /&gt;
                    Console.WriteLine(br.ReadDecimal());&lt;br /&gt;
                    Console.WriteLine(br.ReadString());&lt;br /&gt;
                    Console.WriteLine(br.ReadString());&lt;br /&gt;
                    Console.WriteLine(br.ReadChar());&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;124.23&lt;br /&gt;
Test string&lt;br /&gt;
Test string 2&lt;br /&gt;
!&lt;br /&gt;
Unhandled Exception: System.ObjectDisposedException: Cannot access a closed file.&lt;br /&gt;
   at System.IO.__Error.FileNotOpen()&lt;br /&gt;
   at System.IO.FileStream.Seek(Int64 offset, SeekOrigin origin)&lt;br /&gt;
   at System.IO.FileStream.set_Position(Int64 value)&lt;br /&gt;
   at MainClass.Main()&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Use BinaryReader to read file in binary format==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
class MainClass&lt;br /&gt;
{&lt;br /&gt;
  public static void Main() &lt;br /&gt;
  {&lt;br /&gt;
    FileStream outStream = File.Create(&amp;quot;c:\\BinaryTest.dat&amp;quot;);&lt;br /&gt;
    BinaryWriter bw = new BinaryWriter(outStream);&lt;br /&gt;
    bw.Write( (int) 3);&lt;br /&gt;
    bw.Write( (decimal) 4.5);&lt;br /&gt;
    string s = &amp;quot;Test String&amp;quot;;&lt;br /&gt;
    bw.Write(s);&lt;br /&gt;
    bw.Flush();&lt;br /&gt;
    bw.Close();&lt;br /&gt;
    FileStream inStream = File.OpenRead(&amp;quot;c:\\BinaryTest.dat&amp;quot;);&lt;br /&gt;
    BinaryReader br = new BinaryReader(inStream);&lt;br /&gt;
    int i = br.ReadInt32();&lt;br /&gt;
    decimal d = br.ReadDecimal();&lt;br /&gt;
    string s2 = br.ReadString();&lt;br /&gt;
    Console.WriteLine(i);&lt;br /&gt;
    Console.WriteLine(d);&lt;br /&gt;
    Console.WriteLine(s2);&lt;br /&gt;
    br.Close();&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;3&lt;br /&gt;
4.5&lt;br /&gt;
Test String&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>