java - 将 byte[] 转换为 PDF 文件而不用 Java 保存在本地磁盘中
问题描述
我将字节数组作为输入,它应该转换为 PDF 类型文件而不写入本地系统,这是我的代码:
public File convertToFile(byte[] data) throws IOException, NullPointerException {
FileOutputStream bar = null;
String pathname = "filename.pdf";
File file = new File(pathname);
try (ByteArrayInputStream bais = new ByteArrayInputStream(data);
ByteArrayOutputStream baos = new ByteArrayOutputStream(data.length)) {
bar = new FileOutputStream(file);
int c = 0;
while (c < bais.read()) {
baos.write(data);
baos.writeTo(bar);``
baos.flush();
}
} catch (Exception e) {
e.getMessage();
}
return file;
}
当我运行此代码时,它会返回我的本地路径。
解决方案
推荐阅读
- javascript - 引导工具提示不适用于动态生成的元素
- visual-studio - 如何解决“进程无法访问文件 .ISPAC,因为它正被另一个进程使用”错误?
- sql - RODBC-谁能告诉我为什么这不起作用?
- java - Android - 使用具有静态方法的助手类动态注册/取消注册接收器?
- azure - 附加到 VM 的 azure cli list nic
- node.js - HTML 组件中的数字
- python-3.x - Linux pyarrow 未定义符号
- amazon-s3 - S3:在本地 git-bash 控制台中下载多个文件
- javascript - OnBlur 没有被正确调用 - 笑话酶
- angular - Angular:多个下拉列表