美文网首页
超长base64字符串转pdf文件

超长base64字符串转pdf文件

作者: 郑勇锋 | 来源:发表于2023-02-09 09:27 被阅读0次

这个时候最好直接从文件读取
/**
* 超长base64字符串转pdf文件
* @param filePath
* @throws IOException
*/
public static void base64StringToPdf( String filePath) throws IOException {
File file1 = new File("D://base64.txt");
InputStream in = new FileInputStream(file1);
BASE64Decoder decoder = new BASE64Decoder();
byte[] bytes = new byte[0];
try {
bytes = decoder.decodeBuffer(in);
} catch (IOException e) {

    }
    File file = new File(filePath);
    File path = file.getParentFile();
    if (!path.exists()) {
        boolean b = path.mkdirs();
        if (!b) {

        }
    }
    try{
        ByteArrayInputStream byteInputStream = new ByteArrayInputStream(bytes);
        BufferedInputStream bis = new BufferedInputStream(byteInputStream);
        FileOutputStream fos = new FileOutputStream(file);
        BufferedOutputStream bos = new BufferedOutputStream(fos);

        byte[] buffer = new byte[1024];
        int length = bis.read(buffer);
        while (length != -1) {
            bos.write(buffer, 0, length);
            length = bis.read(buffer);
        }
        bos.flush();

    } catch (Exception e) {
        e.printStackTrace();
    }
}

相关文章

网友评论

      本文标题:超长base64字符串转pdf文件

      本文链接:https://www.haomeiwen.com/subject/dfbckdtx.html