<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.vbex.ru/index.php?action=history&amp;feed=atom&amp;title=VB.Net%2FFile_Directory%2FBinary_File_Read</id>
		<title>VB.Net/File Directory/Binary File Read - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.vbex.ru/index.php?action=history&amp;feed=atom&amp;title=VB.Net%2FFile_Directory%2FBinary_File_Read"/>
		<link rel="alternate" type="text/html" href="http://www.vbex.ru/index.php?title=VB.Net/File_Directory/Binary_File_Read&amp;action=history"/>
		<updated>2026-04-05T13:13:26Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.vbex.ru/index.php?title=VB.Net/File_Directory/Binary_File_Read&amp;diff=838&amp;oldid=prev</id>
		<title> в 16:40, 26 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.vbex.ru/index.php?title=VB.Net/File_Directory/Binary_File_Read&amp;diff=838&amp;oldid=prev"/>
				<updated>2010-05-26T16:40:06Z</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;Версия 16:40, 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://www.vbex.ru/index.php?title=VB.Net/File_Directory/Binary_File_Read&amp;diff=839&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://www.vbex.ru/index.php?title=VB.Net/File_Directory/Binary_File_Read&amp;diff=839&amp;oldid=prev"/>
				<updated>2010-05-26T12:45:20Z</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;==Check Files Are Identical==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;vbnet&amp;quot;&amp;gt;  &lt;br /&gt;
Public Class MainClass&lt;br /&gt;
    Public Shared Function CompareFiles(ByVal File1 As String, ByVal File2 As String) As Boolean&lt;br /&gt;
        Dim blnIdentical As Boolean = True&lt;br /&gt;
        Dim objFS1 As System.IO.FileStream = New System.IO.FileStream(File1, System.IO.FileMode.Open)&lt;br /&gt;
        Dim objFS2 As System.IO.FileStream = New System.IO.FileStream(File2, System.IO.FileMode.Open)&lt;br /&gt;
        If (objFS1.Length &amp;lt;&amp;gt; objFS2.Length) Then&lt;br /&gt;
            blnIdentical = False&lt;br /&gt;
        Else&lt;br /&gt;
            Dim intByteF1 As Integer&lt;br /&gt;
            Dim intByteF2 As Integer&lt;br /&gt;
            Do&lt;br /&gt;
                intByteF1 = objFS1.ReadByte()&lt;br /&gt;
                intByteF2 = objFS2.ReadByte()&lt;br /&gt;
                If intByteF1 &amp;lt;&amp;gt; intByteF2 Then&lt;br /&gt;
                    blnIdentical = False&lt;br /&gt;
                    Exit Do&lt;br /&gt;
                End If&lt;br /&gt;
            Loop While (intByteF1 &amp;lt;&amp;gt; -1)&lt;br /&gt;
        End If&lt;br /&gt;
        objFS1.Close()&lt;br /&gt;
        objFS2.Close()&lt;br /&gt;
        Return blnIdentical&lt;br /&gt;
    End Function&lt;br /&gt;
    Public Shared Sub Main()&lt;br /&gt;
        If CompareFiles(&amp;quot;1.jpg&amp;quot;, &amp;quot;2.bmp&amp;quot;) Then&lt;br /&gt;
            System.Console.WriteLine(&amp;quot;Files are identical!&amp;quot;)&lt;br /&gt;
        Else&lt;br /&gt;
            System.Console.WriteLine(&amp;quot;Files do not match!&amp;quot;)&lt;br /&gt;
        End If&lt;br /&gt;
    End Sub&lt;br /&gt;
End Class&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Read and Write Binary file: int, string ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;vbnet&amp;quot;&amp;gt; &lt;br /&gt;
Imports System.IO&lt;br /&gt;
Module Module1&lt;br /&gt;
    Sub Main()&lt;br /&gt;
        Dim Stream As FileStream&lt;br /&gt;
        Try&lt;br /&gt;
            Stream = New FileStream(&amp;quot;test.dat&amp;quot;, FileMode.Create)&lt;br /&gt;
        Catch E As Exception&lt;br /&gt;
            Console.WriteLine(&amp;quot;Error creating test.Dat&amp;quot;)&lt;br /&gt;
            Console.WriteLine(&amp;quot;Error {0}&amp;quot;, E.Message)&lt;br /&gt;
        End Try&lt;br /&gt;
        Dim BinaryStream As New BinaryWriter(Stream)&lt;br /&gt;
        Dim Age As Integer = 21&lt;br /&gt;
        Dim Salary As Double = 100000.0&lt;br /&gt;
        Dim Name As String = &amp;quot;Joe&amp;quot;&lt;br /&gt;
        Try&lt;br /&gt;
            BinaryStream.Write(Age)&lt;br /&gt;
            BinaryStream.Write(Salary)&lt;br /&gt;
            BinaryStream.Write(Name)&lt;br /&gt;
            BinaryStream.Close()&lt;br /&gt;
            Console.WriteLine(&amp;quot;Data written to test.Dat&amp;quot;)&lt;br /&gt;
        Catch E As Exception&lt;br /&gt;
            Console.WriteLine(&amp;quot;Error writing to test.Dat&amp;quot;)&lt;br /&gt;
            Console.WriteLine(&amp;quot;Error {0}&amp;quot;, E.Message)&lt;br /&gt;
        End Try&lt;br /&gt;
        &lt;br /&gt;
        &amp;quot;Read &lt;br /&gt;
        &lt;br /&gt;
        Try&lt;br /&gt;
            Stream = New FileStream(&amp;quot;test.dat&amp;quot;, FileMode.Open)&lt;br /&gt;
        Catch E As Exception&lt;br /&gt;
            Console.WriteLine(&amp;quot;Error opening test.Dat&amp;quot;)&lt;br /&gt;
            Console.WriteLine(&amp;quot;Error {0}&amp;quot;, E.Message)&lt;br /&gt;
        End Try&lt;br /&gt;
        Dim BinaryStreamReader As New BinaryReader(Stream)&lt;br /&gt;
        Try&lt;br /&gt;
            Age = BinaryStreamReader.ReadInt32()&lt;br /&gt;
            Salary = BinaryStreamReader.ReadDouble()&lt;br /&gt;
            Name = BinaryStreamReader.ReadString()&lt;br /&gt;
            BinaryStreamReader.Close()&lt;br /&gt;
            Console.WriteLine(&amp;quot;Age: {0}&amp;quot;, Age)&lt;br /&gt;
            Console.WriteLine(&amp;quot;Salary: {0}&amp;quot;, Salary)&lt;br /&gt;
            Console.WriteLine(&amp;quot;Name: {0}&amp;quot;, Name)&lt;br /&gt;
        Catch E As Exception&lt;br /&gt;
            Console.WriteLine(&amp;quot;Error reading to test.Dat&amp;quot;)&lt;br /&gt;
            Console.WriteLine(&amp;quot;Error {0}&amp;quot;, E.Message)&lt;br /&gt;
        End Try&lt;br /&gt;
    End Sub&lt;br /&gt;
End Module&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
         &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Read from a binary file==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;vbnet&amp;quot;&amp;gt; &lt;br /&gt;
Imports System&lt;br /&gt;
Imports System.IO&lt;br /&gt;
Imports System.Windows.Forms&lt;br /&gt;
Public Class MainClass&lt;br /&gt;
   Shared Sub Main()&lt;br /&gt;
        Dim emp As New Employee&lt;br /&gt;
        Dim file_num As Integer = FreeFile()&lt;br /&gt;
        FileOpen(file_num, &amp;quot;MYFILE.DAT&amp;quot;, OpenMode.Random, _&lt;br /&gt;
             OpenAccess.ReadWrite, OpenShare.Shared, _&lt;br /&gt;
             Len(emp))&lt;br /&gt;
        FilePut(file_num, New Employee(1, &amp;quot;A&amp;quot;, &amp;quot;A&amp;quot;))&lt;br /&gt;
        FilePut(file_num, New Employee(2, &amp;quot;B&amp;quot;, &amp;quot;B&amp;quot;))&lt;br /&gt;
        FilePut(file_num, New Employee(3, &amp;quot;C&amp;quot;, &amp;quot;C&amp;quot;))&lt;br /&gt;
        FilePut(file_num, New Employee(4, &amp;quot;D&amp;quot;, &amp;quot;D&amp;quot;))&lt;br /&gt;
        FilePut(file_num, New Employee(5, &amp;quot;E&amp;quot;, &amp;quot;E&amp;quot;))&lt;br /&gt;
        FilePut(file_num, New Employee(6, &amp;quot;F&amp;quot;, &amp;quot;F&amp;quot;))&lt;br /&gt;
        Dim obj As ValueType = DirectCast(emp, ValueType)&lt;br /&gt;
        For Each i As Integer In New Integer() {3, 1, 5, 2, 6}&lt;br /&gt;
            FileGet(file_num, obj, i)&lt;br /&gt;
            emp = DirectCast(obj, Employee)&lt;br /&gt;
            Console.WriteLine(emp.ToString())&lt;br /&gt;
        Next i&lt;br /&gt;
        &amp;quot; Close the file.&lt;br /&gt;
        FileClose(file_num)&lt;br /&gt;
   End Sub &lt;br /&gt;
End Class&lt;br /&gt;
    Public Structure Employee&lt;br /&gt;
        Public ID As Integer&lt;br /&gt;
        &amp;lt;VBFixedString(15)&amp;gt; Public FirstName As String&lt;br /&gt;
        &amp;lt;VBFixedString(15)&amp;gt; Public LastName As String&lt;br /&gt;
        Public Sub New(ByVal new_id As Integer, ByVal first_name As String, _&lt;br /&gt;
         ByVal last_name As String)&lt;br /&gt;
            ID = new_id&lt;br /&gt;
            FirstName = first_name&lt;br /&gt;
            LastName = last_name&lt;br /&gt;
        End Sub&lt;br /&gt;
        Public Overrides Function ToString() As String&lt;br /&gt;
            Return ID &amp;amp; &amp;quot;: &amp;quot; &amp;amp; FirstName &amp;amp; &amp;quot; &amp;quot; &amp;amp; LastName&lt;br /&gt;
        End Function&lt;br /&gt;
    End Structure&lt;br /&gt;
           &lt;br /&gt;
         &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Reading a sequential-access file==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;vbnet&amp;quot;&amp;gt; &lt;br /&gt;
Imports System.IO&lt;br /&gt;
Imports System.Collections&lt;br /&gt;
Imports System.Windows.Forms&lt;br /&gt;
Imports System.Runtime.Serialization.Formatters.Binary&lt;br /&gt;
Imports System.Runtime.Serialization&lt;br /&gt;
Public Class MainClass&lt;br /&gt;
   Public Shared Sub Main()&lt;br /&gt;
         Dim formatter As BinaryFormatter = New BinaryFormatter()&lt;br /&gt;
         Dim output As FileStream&lt;br /&gt;
         Dim fileName As String = &amp;quot;test.dat&amp;quot;&lt;br /&gt;
         Dim employee As Employee = New Employee(&amp;quot;First Name&amp;quot;, &amp;quot;Last Name&amp;quot;)&lt;br /&gt;
         Try&lt;br /&gt;
            output = New FileStream(fileName,FileMode.OpenOrCreate, FileAccess.Write)&lt;br /&gt;
  &lt;br /&gt;
            formatter.Serialize(output, employee)&lt;br /&gt;
            output.Close()&lt;br /&gt;
  &lt;br /&gt;
         Catch fileException As FileNotFoundException&lt;br /&gt;
            Console.WriteLine(&amp;quot;File Does Not Exits&amp;quot;)&lt;br /&gt;
         Catch serializableException As SerializationException&lt;br /&gt;
            Console.WriteLine(&amp;quot;Error Writing to File&amp;quot;)&lt;br /&gt;
         Catch formattingException As FormatException&lt;br /&gt;
            Console.WriteLine(&amp;quot;Invalid Format&amp;quot;)&lt;br /&gt;
         Catch e As IOException&lt;br /&gt;
            Console.WriteLine(&amp;quot;Cannot close file&amp;quot;)&lt;br /&gt;
         End Try&lt;br /&gt;
&lt;br /&gt;
         Dim input As FileStream&lt;br /&gt;
         Dim reader As BinaryFormatter = New BinaryFormatter()&lt;br /&gt;
         input = New FileStream(fileName, FileMode.Open,FileAccess.Read)&lt;br /&gt;
         Try&lt;br /&gt;
             Dim em As Employee = CType(reader.Deserialize(input), Employee)&lt;br /&gt;
         &lt;br /&gt;
             Console.WriteLine(em)&lt;br /&gt;
         Catch serializableException As SerializationException&lt;br /&gt;
             input.Close() &lt;br /&gt;
             Console.WriteLine(&amp;quot;No more records in file&amp;quot;)&lt;br /&gt;
         End Try&lt;br /&gt;
   End Sub&lt;br /&gt;
End Class&lt;br /&gt;
&amp;lt;Serializable()&amp;gt; Public Class Employee&lt;br /&gt;
   Private firstName, lastName As String&lt;br /&gt;
   Public Sub New(ByVal first As String, ByVal last As String)&lt;br /&gt;
      firstName = first&lt;br /&gt;
      lastName = last&lt;br /&gt;
   End Sub &lt;br /&gt;
   Public Overrides Function ToString() As String&lt;br /&gt;
      Return firstName &amp;amp; &amp;quot; &amp;quot; &amp;amp; lastName&lt;br /&gt;
   End Function &lt;br /&gt;
End Class &lt;br /&gt;
           &lt;br /&gt;
         &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>