我在将一些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);