将VB.NET base64转换代码转换为Java等价物

时间:2015-01-07 08:45:46

标签: java android vb.net

我在将一些VB.NET代码转换为Java时遇到了麻烦。对于同一输入文件,转换结果并不相同。

VB.NET

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))
    Dim results as String = Convert.ToBase64String(BinBytes)
    BinaryFile.Close()
End Using

Java(Android)

File file =  new File( "/sdcard/a.jpg" ) ;  
byte[] fileData = new byte[(int) file.length()];
String result = Base64.encodeToString(fileData, Base64.DEFAULT);

0 个答案:

没有答案