OutputStream ou = null;
InputStream in = null;
try {
in = new FileInputStream(sdPath + "/12.jpg");
byte[] buffer = new byte[1024 * 100];
int index = 0;
int length = 0;
while ((length = in.read(buffer)) != -1) {
File file = new File(sdPath + "/base64-" + index + ".txt");
if (!file.exists()) {
file.createNewFile();
}
ou = new FileOutputStream(file);
ou.write(Base64.encode(buffer, Base64.NO_PADDING));
index++;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
in.close();
ou.flush();
ou.close();
} catch (IOException e) {
e.printStackTrace();
}
}
android 图片转 Base64
最新推荐文章于 2023-02-24 10:25:42 发布
本文详细介绍了如何利用Java的FileInputStream和FileOutputStream类结合Base64编码,实现对指定目录下多个图片文件的批量读取、转换并保存为Base64字符串的过程。通过此方法,可以有效地将图片数据转化为便于网络传输或存储的形式,提高数据处理的效率。
528

被折叠的 条评论
为什么被折叠?



