将文件转成base64 字符串

2022年6月6日12:15:41
    /*
     *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) file.length()];
		inputFile.read(buffer);
		inputFile.close();
		return new BASE64Encoder().encode(buffer);
	}
    /*
     *actions: 将base64字符保存文本文件
	 *targetPath:文件路径
	 *base64Code: base64字符串
	 */
	public void toFile(String base64Code, String targetPath) throws Exception {
		byte[] buffer = base64Code.getBytes();
		FileOutputStream out = new FileOutputStream(targetPath);
		out.write(buffer);
		out.close();
	}
  • 作者:秋风未动蝉已先觉
  • 原文链接:https://blog.csdn.net/weixin_40764017/article/details/123334144
    更新时间:2022年6月6日12:15:41 ,共 539 字。