vb.net - 将文件转换为base64函数输出

标签 vb.net file base64

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”
  • 最佳答案

       Public Function ConvertFileToBase64(ByVal fileName As String) As String
            Return Convert.ToBase64String(System.IO.File.ReadAllBytes(fileName))
        End Function
    

    关于vb.net - 将文件转换为base64函数输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10739264/

    相关文章:

    python - 覆盖以前提取的文件而不是创建新文件

    c# - 如何使用 "user32.dll"函数读取消息框内容文本

    c# - HtmlWindow.Error 未捕获脚本错误 .NET

    VB.NET VScrollBar,反向功能

    c# - 如何从 C# 或 VB.Net 使用 Win32 'DwmSetIconicThumbnail'?

    c++ - 将结构写入文件

    linux - 理解标准输出、标准错误和标准输入

    python - 解码python base64字符串

    java - 打开移位 : maven compiler error : Base64 can not find the symbol

    python - 这个字符串是 Base64 吗?我怎么知道使用的编码是什么?