使⽤Base64将字节数组编码成字符串,或者将字符串解码成字
节数组
⼀、根据图⽚的url将图⽚读⼊字节输⼊流中,然后将字节输⼊流中的内容读取到字节数组中,再将字节数组通过Base64编码成字符串Map resultMap = new HashMap();
List<String> images = new ArrayList<>();
//根据采购订单详细获取样本图⽚,转为字节流
List<AttachFile> fileList = FileList(inDetailId, "B_IN_DETAIL", "BIDSAMPLE_IMG");
fileList.stream().forEach(file -> {
String url = shareFile + "/" + UploadPath() + "/" + CompressedName();
try (InputStream in = new BufferedInputStream(new FileInputStream(url))) {
byte[] srcBytes = new byte[in.available()];
images.Encoder().encodeToString(srcBytes));
} catch (Exception e) {
<("图⽚转换流异常:" + e.getMessage());
}
将数组格式的字符串转换成数组});
resultMap.put("IMAGES", images);
return resultMap;
⼆、将JSON字符串转换成字节数组,然后将字节数组中的内容通过字节输出流写⼊⽂件中
//将字符串转换为byte数组
byte[] bytes = Decoder().im());
File file = new File(dir + "/" + fileName);
FileOutputStream fos = new FileOutputStream(file);
BufferedOutputStream bos = new BufferedOutputStream(fos);
bos.write(bytes);
if (bos != null) {
bos.close();
}
if (fos != null) {
fos.close();
}
引⼊Base64:
import java.util.Base64
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论