<?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_Write</id>
		<title>VB.Net/File Directory/Binary File Write - История изменений</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_Write"/>
		<link rel="alternate" type="text/html" href="http://www.vbex.ru/index.php?title=VB.Net/File_Directory/Binary_File_Write&amp;action=history"/>
		<updated>2026-04-05T13:13:00Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.vbex.ru/index.php?title=VB.Net/File_Directory/Binary_File_Write&amp;diff=836&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_Write&amp;diff=836&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_Write&amp;diff=837&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_Write&amp;diff=837&amp;oldid=prev"/>
				<updated>2010-05-26T12:45:19Z</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;==Creating a random file==&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;
      Const NUMBER_OF_RECORDS As Integer = 100&lt;br /&gt;
      &amp;quot; record for writing to disk&lt;br /&gt;
      Dim blankRecord As Employee = New Employee(&amp;quot;f&amp;quot;,&amp;quot;l&amp;quot;)&lt;br /&gt;
      Dim fileOutput As FileStream&lt;br /&gt;
      Dim binaryOutput As BinaryWriter&lt;br /&gt;
      Dim fileName As String = &amp;quot;test.dat&amp;quot;&lt;br /&gt;
      Dim i As Integer&lt;br /&gt;
         Try&lt;br /&gt;
            fileOutput = New FileStream(fileName,FileMode.Create, FileAccess.Write)&lt;br /&gt;
            fileOutput.SetLength(Employee.SIZE * NUMBER_OF_RECORDS)&lt;br /&gt;
            binaryOutput = New BinaryWriter(fileOutput)&lt;br /&gt;
            For i = 0 To NUMBER_OF_RECORDS - 1&lt;br /&gt;
               fileOutput.Position = i * Employee.SIZE&lt;br /&gt;
               binaryOutput.Write(blankRecord.firstName)&lt;br /&gt;
               binaryOutput.Write(blankRecord.lastName)&lt;br /&gt;
            Next&lt;br /&gt;
            Console.WriteLine(&amp;quot;File Created&amp;quot;)&lt;br /&gt;
         Catch fileException As IOException&lt;br /&gt;
            Console.WriteLine(&amp;quot;Cannot write to file&amp;quot;)&lt;br /&gt;
         End Try&lt;br /&gt;
&lt;br /&gt;
      &amp;quot; close FileStream&lt;br /&gt;
      If (fileOutput Is Nothing) &amp;lt;&amp;gt; False Then&lt;br /&gt;
         fileOutput.Close()&lt;br /&gt;
      End If&lt;br /&gt;
      &amp;quot; close BinaryWriter&lt;br /&gt;
      If (binaryOutput Is Nothing) &amp;lt;&amp;gt; False Then&lt;br /&gt;
         binaryOutput.Close()&lt;br /&gt;
      End If&lt;br /&gt;
   End Sub&lt;br /&gt;
End Class&lt;br /&gt;
&amp;lt;Serializable()&amp;gt; Public Class Employee&lt;br /&gt;
   Public firstName, lastName As String&lt;br /&gt;
   Shared Public SIZE As Integer = 200 &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;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Save Structure to a Binary File==&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;
&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;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Use BinaryWriter to store information into a binary file==&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;
Public Class MainClass&lt;br /&gt;
  Shared Sub Main()&lt;br /&gt;
    Dim aFileStream As FileStream&lt;br /&gt;
    Try&lt;br /&gt;
      aFileStream = New FileStream(&amp;quot;test.txt&amp;quot;, FileMode.OpenOrCreate,FileAccess.Write)&lt;br /&gt;
      Dim myBinaryWriter As New BinaryWriter(aFileStream)&lt;br /&gt;
      myBinaryWriter.Write(&amp;quot;Hello world&amp;quot;)&lt;br /&gt;
      myBinaryWriter.Write(1)&lt;br /&gt;
    Catch e As Exception&lt;br /&gt;
      Console.WriteLine(e.StackTrace)&lt;br /&gt;
    Finally&lt;br /&gt;
      If Not (aFileStream Is Nothing) Then aFileStream.Close()&lt;br /&gt;
    End Try&lt;br /&gt;
  End Sub&lt;br /&gt;
  &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>