本文整理汇总了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
示例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