我想字节转换为字符串和背部,我已经试过这样:字节>字符串>字节>文件VB
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim bytes() As Byte = My.Computer.FileSystem.ReadAllBytes("C:\Archive.zip")
Dim filestream As System.IO.FileStream = System.IO.File.Create("C:\Archive2.zip")
Dim info As Byte() = fromstringtobyte(frombytetostring(bytes))
filestream.Write(info, 0, info.Length)
filestream.Close()
End Sub
Private Function frombytetostring(ByVal b() As Byte)
Dim s As String
s = Convert.ToBase64String(b)
Return s
End Function
Private Function fromstringtobyte(ByVal s As String)
Dim b() As Byte
b = System.Text.Encoding.UTF8.GetBytes(s)
Return b
End Function
End Class
已创建已损坏的新文件。 你能推荐任何其他解决方案吗?
对不起,我的英语不好,这不是我的主要语言。
我如何知道使用哪种编码? –
您需要在字符串到字节和字节到字符串中使用相同的编码。你选择哪一个取决于各种因素。看到我发布的链接。 –
你发布了什么链接? –