Java将二进制流转Base64字符串并在页面显示(附Base64转二进制流)
java代码如下:
/**
* 二进制流转Base64字符串
*
* @param data 二进制流
* @return data
* @throws IOException 异常
*/
public static String getImageString(byte[] data) throws IOException {
BASE64Encoder encoder = new BASE64Encoder();
return data != null ? encoder.encode(data) : “”;
}
/**
* Base64字符串转 二进制流
*
* @param base64String Base64
* @return base64String
* @throws IOException 异常
*/
public static byte[] getStringImage(String base64String) throws IOException {
BASE64Decoder decoder = new sun.misc.BASE64Decoder();
return base64String != null ? decoder.decodeBuffer(base64String) : null;
}
————————————————
版权声明:本文为CSDN博主「QC班长」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_35624642/article/details/52193743