在 java 中执行以下操作时,我在 0: 37(decimal) 异常处得到 Bad Base64 输入字符。
static void byteArrayToFile(byte[] bArray) {
try {
// Create file
String pathName = AppConfig.getInstance().getConfigValue("webapp.root") + File.separator + "temp"+File.separator+"heasas.pdf";
FileWriter fstream = new FileWriter(pathName);
BufferedWriter out = new BufferedWriter(fstream);
for (Byte b: bArray) {
out.write(b);
}
out.close();
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
大家好, 在收到来自第 3 方的 Soap 消息时,我编写了以下代码片段来获取附件内容: Object content = attachment1.getContent(); 写PDF(内容);
private void writePdf(Object content) throws IOException, PrintException, DocumentException {
String str = content.toString();
byte[] b = Base64.decode(str);
byteArrayToFile(b);
}
这是我将字节数组转换为pdf的逻辑:
static void byteArrayToFile(byte[] bArray) {
try {
// Create file
String pathName = AppConfig.getInstance().getConfigValue("webapp.root") + File.separator + "temp"+File.separator+"heasas.pdf";
FileWriter fstream = new FileWriter(pathName);
BufferedWriter out = new BufferedWriter(fstream);
for (Byte b: bArray) {
out.write(b);
}
out.close();
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
任何人都可以建议我现在的解决方案......