【发布时间】:2018-08-16 15:01:19
【问题描述】:
我需要将 PDF 内容转换为 Base64 并将其用作字符串。 当我使用下面的程序测试 out.pdf 变为空白。
byte[] pdfRawData = FileUtils.readFileToByteArray(new File("C:\\in.pdf")) ;
String pdfStr = new String(pdfRawData);
//My data is available in the form of String
BASE64Encoder encoder = new BASE64Encoder();
String encodedPdf = encoder.encode(pdfStr.getBytes());
System.out.println(encodedPdf);
// Decode the encoded content to test
BASE64Decoder decoder = new BASE64Decoder();
FileUtils.writeByteArrayToFile(new File("C:\\out.pdf") , decoder.decodeBuffer(encodedPdf));
谁能帮帮我?
【问题讨论】: