[英]how i can read files as bytes then encode it to base64 in java ( android )
How can I read files as bytes and then encode it to base64 by java with low api like : api level 17?如何将文件作为字节读取,然后通过具有低 api 的 java 将其编码为 base64,例如:api level 17?
I tried this code to convert files to base64:我尝试使用此代码将文件转换为 base64:
Java Encode file to Base64 string To match with other encoded string Java 将文件编码为 Base64 字符串以匹配其他编码字符串
File file = new File(filepath);
byte[] fileContent = Files.readAllBytes(file.toPath());
String encodedString = Base64.getEncoder().encodeToString(fileContent.getBytes());
For old api use FileUtils.readFileToByteArray(File file)
or IOUtils.toByteArray(InputStream input)
.对于旧 API,请使用IOUtils.toByteArray(InputStream input)
FileUtils.readFileToByteArray(File file)
或IOUtils.toByteArray(InputStream input)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.