这个时候最好直接从文件读取
/**
* 超长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();
}
}