gpt4 book ai didi

android - 如何将文件转换为Base64?

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:21:17 25 4
gpt4 key购买 nike

这里的报告包含路径(字符串格式的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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com