我使用vb .NET函数ReadAllBytes来读取文件并通过套接字发送它。收到后,我使用了WriteAllBytes。问题是它们的大小不一样!原始是16kb,但接收的数据是24kb。我的代码如下。我做错了什么?
Dim bteRead() As Byte
Try
bteRead = IO.File.ReadAllBytes(filepath)
Catch ex As System.IO.IOException
End Try
Return bteRead
然后我将字节转换为字符串并发送它,并在收到后将其从字符串转换回字节并执行WriteAllBytes
Dim str As String = a(1)
Dim encod As New System.Text.UTF8Encoding
Dim byteData() As Byte = encod.GetBytes(str)
IO.File.WriteAllBytes("c:\lol.db", byteData)
答案 0 :(得分:1)
我的解决方案是改变:
Dim encod As New System.Text.UTF8Encoding
Dim byteData() As Byte = encod.GetBytes(str)
要
Dim byteData() As Byte = System.Text.Encoding.Default.GetBytes(str)