base64转pdf文件

//base64转pdf文件
Base64ToImageUtil.base64ToImage(pdfStr, localUrl + base64PDFFileName);


public static String base64ToImage(String base64, String path) throws Exception {

        try (OutputStream out = new FileOutputStream(path)) {
            byte[] data = new BASE64Decoder().decodeBuffer(base64);
            for (int i = 0; i < data.length; ++i) {
                if (data[i] < 0) {
                    // 调整异常数据
                    data[i] += 256;
                }
            }
            out.write(data);
            out.flush();
        } catch (IOException e) {
            throw (Exception) e.fillInStackTrace();
        }
        File file = new File(path);
        if(file.exists()){
            return path;
        }
        return "";
    }

 

posted @ 2023-05-09 14:57  噗噗噗i丶  阅读(799)  评论(0编辑  收藏  举报