作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
这里的报告包含路径(字符串格式的sdcard中的路径名)
File dir = Environment.getExternalStorageDirectory();
File yourFile = new File(dir, report);
String encodeFileToBase64Binary = encodeFileToBase64Binary(yourFile);
private static String encodeFileToBase64Binary(File fileName) throws IOException {
byte[] bytes = loadFile(fileName);
byte[] encoded = Base64.encodeBase64(bytes);
String encodedString = new String(encoded);
return encodedString;
}
在 byte[] 编码行中出现此错误。Base64 类型未定义方法 encodeBase64(byte[])
最佳答案
String value = Base64.encodeToString(bytes, Base64.DEFAULT);
但您可以直接将其转换为 String 。希望这对您有用。
关于android - 如何将文件转换为Base64?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28758014/
我是一名优秀的程序员,十分优秀!