none
Base 64 轉換 RRS feed

解答

  • Public Sub EncodeWithString()
       Dim inFile As System.IO.FileStream
       Dim binaryData() As Byte

       Try
          inFile = New System.IO.FileStream(inputFileName, System.IO.FileMode.Open, System.IO.FileAccess.Read)
          ReDim binaryData(inFile.Length)
          Dim bytesRead As Long = inFile.Read(binaryData, 0,inFile.Length)
          inFile.Close()
       Catch exp As System.Exception
               Return
       End Try

       ' Convert the binary input into Base64 UUEncoded output.
       Dim base64String As String
       Try
          base64String = System.Convert.ToBase64String(binaryData, 0,binaryData.Length)
       Catch exp As System.ArgumentNullException
              Return
       End Try

       ' Write the UUEncoded version to the output file.
       Dim outFile As System.IO.StreamWriter
       Try
          outFile = New System.IO.StreamWriter(outputFileName,False, System.Text.Encoding.ASCII)
          outFile.Write(base64String)
          outFile.Close()
       Catch exp As System.Exception
         End Try
    End Sub

    2008年10月12日 下午 01:56