public void t04() throws IOException {
// 文件 转 base64字符串(FileUtil和Base64Decoder都来自hutool)
byte[] bytes = FileUtil.readBytes("d:\\tmp2\\3.jpg");
String s = Base64Encoder.encode(bytes);
System.out.println("s = " + s);///9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAMCAg...
// base64字符串 转 文件
byte[] decode = Base64Decoder.decode(s);
File file = FileUtil.writeBytes(decode,"d:/tmp2/18.jpg");
}
base64字符串与图片文件保存互转
最新推荐文章于 2024-06-19 11:06:32 发布