以下のコードを使用してバイナリ ファイルからバイナリ データを読み込もうとしていますが、値はバイト配列で返されます。バイナリ ファイルからバイナリ データを読み取り、そのデータを文字列に変換するにはどうすればよいですか?
これは、バイナリファイルを作成する方法です。
Dim fs As New FileStream(Application.StartupPath & "\Agency.dat", FileMode.OpenOrCreate)
Dim bf As New BinaryFormatter()
Call bf.Serialize(fs, GAgency)
fs.Close()
バイナリ ファイルを読み取るコード。
Public Shared Function ReadBinaryFile(ByVal path As String)
' Open the binary file.
Dim streamBinary As New FileStream(path, FileMode.Open)
' Create a binary stream reader object.
Dim readerInput As BinaryReader = New BinaryReader(streamBinary)
' Determine the number of bytes to read.
Dim lengthFile As Integer = FileSize(path)
' Read the data in a byte array buffer.
Dim inputData As Byte() = readerInput.ReadBytes(lengthFile)
' Close the file.
streamBinary.Close()
readerInput.Close()
Return inputData
End Function 'ReadBinaryData’