[英]Vb.net System.IO.File.ReadAllBytes throws error when there is space in file name
[英]Using vb.net ReadAllBytes
我使用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)
我的解決方案是更改:
Dim encod As New System.Text.UTF8Encoding
Dim byteData() As Byte = encod.GetBytes(str)
至
Dim byteData() As Byte = System.Text.Encoding.Default.GetBytes(str)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.