Java - 将文件转成base64 字符串

时间:2025-03-12 09:26:15
/* *actions: 将文件转成base64 字符串 *path:文件路径 */ public String encodeBase64File(String path) throws Exception { File file = new File(path); FileInputStream inputFile = new FileInputStream(file); byte[] buffer = new byte[(int) ()]; (buffer); (); return new BASE64Encoder().encode(buffer); } /* *actions: 将base64字符保存文本文件 *targetPath:文件路径 *base64Code: base64字符串 */ public void toFile(String base64Code, String targetPath) throws Exception { byte[] buffer = (); FileOutputStream out = new FileOutputStream(targetPath); (buffer); (); }