我是宋青书:如何把一个文本文件转换成二进制格式?

来源:百度文库 编辑:高校问答 时间:2024/04/29 08:00:44
如何把一个文本文件转换成二进制格式?

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim b As New FileStream("123.txt", FileMode.Create, FileAccess.Write) ' filemoad.create 创建文件,fileaccess.write能够向文件写入。
Dim a As New StreamWriter(b) 'streamwrite写入文本
Try
a.WriteLine("here is the text")
a.Write("this text is stored in a file ." & ControlChars.CrLf)
a.WriteLine("and now you can read it.")
a.Close()
MsgBox("wrote text data to the file .")
Catch ex As IOException
MsgBox(ex.Message)
End Try
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim c As New FileStream("123.txt", FileMode.Open, FileAccess.Read)
Dim d As New StreamReader(c)
Try
While d.Peek() > -1
textbox1.text &= d.ReadLine() & ControlChars.CrLf
End While
d.Close()
Catch ex As IOException
MsgBox(ex.Message)
End Try
End Sub