/**
* 将图片Base64编码转换成img图片文件
*
* @param imgBase64 图片Base64编码
* @param imgPath 图片生成路径
* @return
*/
public static boolean getImgBase64ToImgFile(String imgBase64, String imgPath) {
boolean flag = true;
OutputStream outputStream = null;
try {
// 解密处理数据
byte[] bytes = Base64.getDecoder().decode(imgBase64);
for (int i = 0; i < bytes.length; ++i) {
if (bytes[i] < 0) {
bytes[i] += 256;
}
}
outputStream = new FileOutputStream(imgPath);
outputStream.write(bytes);
} catch (Exception e) {
e.printStackTrace();
flag = false;
} finally {
if (outputStream != null) {
try {
// 关闭outputStream流
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return flag;
}
请查看站内文章 ---> Java将网络链接图片或者本地图片文件转换成Base64编码字符串