Public Function ConvertFileToBase64(ByVal fileName As String) As String
Dim ReturnValue As String = ""
If My.Computer.FileSystem.FileExists(fileName) Then
Using BinaryFile As FileStream = New FileStream(fileName, FileMode.Open)
Dim BinRead As BinaryReader = New BinaryReader(BinaryFile)
Dim BinBytes As Byte() = BinRead.ReadBytes(CInt(BinaryFile.Length))
ReturnValue = Convert.ToBase64String(BinBytes)
BinaryFile.Close()
End Using
End If
Return ReturnValue
End Function
我想问的问题:
- 我想要将文本文件“C:\Users\user\Desktop\rats\test\test.txt”转换为base64的输出
- 当我将“test.txt”转换为 base64 时,我无法获得任何输出
- 我使用 filename="textbox1.text" 添加我的“test.txt”