当前位置: 首页>>代码示例>>VB.NET>>正文


VB.NET BinaryWriter类代码示例

本文整理汇总了VB.NET中System.IO.BinaryWriter的典型用法代码示例。如果您正苦于以下问题:VB.NET BinaryWriter类的具体用法?VB.NET BinaryWriter怎么用?VB.NET BinaryWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了BinaryWriter类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。

示例1: Module1

' 导入命名空间
Imports System.IO

Module Module1
    Const fileName As String = "AppSettings.dat"

    Sub Main()
        WriteDefaultValues()
        DisplayValues()
    End Sub

    Sub WriteDefaultValues()
        Using writer As BinaryWriter = New BinaryWriter(File.Open(fileName, FileMode.Create))
            writer.Write(1.25F)
            writer.Write("c:\Temp")
            writer.Write(10)
            writer.Write(True)
        End Using
    End Sub

    Sub DisplayValues()
        Dim aspectRatio As Single
        Dim tempDirectory As String
        Dim autoSaveTime As Integer
        Dim showStatusBar As Boolean

        If (File.Exists(fileName)) Then

            Using reader As BinaryReader = New BinaryReader(File.Open(fileName, FileMode.Open))
                aspectRatio = reader.ReadSingle()
                tempDirectory = reader.ReadString()
                autoSaveTime = reader.ReadInt32()
                showStatusBar = reader.ReadBoolean()
            End Using

            Console.WriteLine("Aspect ratio set to: " & aspectRatio)
            Console.WriteLine("Temp directory is: " & tempDirectory)
            Console.WriteLine("Auto save time set to: " & autoSaveTime)
            Console.WriteLine("Show status bar: " & showStatusBar)
        End If
    End Sub

End Module
开发者ID:VB.NET开发者,项目名称:System.IO,代码行数:43,代码来源:BinaryWriter

示例2: New BinaryWriter(FileStream aFileStream)

' 导入命名空间
Imports System
Imports System.IO

Public Class MainClass

  Shared Sub Main()

    Dim aFileStream As FileStream
    Try
      aFileStream = New FileStream("test.txt", FileMode.OpenOrCreate,FileAccess.Write)
      Dim myBinaryWriter As New BinaryWriter(aFileStream)
      myBinaryWriter.Write("Hello world")
      myBinaryWriter.Write(1)
    Catch e As Exception
      Console.WriteLine(e.StackTrace)
    Finally
      If Not (aFileStream Is Nothing) Then aFileStream.Close()
    End Try
  End Sub
  
End Class
开发者ID:VB程序员,项目名称:System.IO,代码行数:22,代码来源:BinaryWriter


注:本文中的System.IO.BinaryWriter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。