将base64码转换为文件
public toPng(String text) throws IOException {
//获取解码器
Base64.Decoder decoder = Base64.getDecoder();
//选择文件保存的位置
FileOutputStream fileOutputStream = new FileOutputStream(new File("输出路径\\123.png"));
//写入
fileOutputStream.write(decoder.decode(text));
//关闭流
fileOutputStream.close();
}
将文件转换为base64码
public void toBase()throws Exception{
//获得Base64的编码器
Base64.Encoder encoder = Base64.getEncoder();
//选择需要转为Base64编码的文件
//文件输入流
FileInputStream fis = new FileInputStream(new File("1.png"));
//编码为String字符串
String s = encoder.encodeToString(fis.readAllBytes());
//关闭流
fis.close();
}