【发布时间】:2021-10-24 05:46:12
【问题描述】:
我正在尝试在生成字节数组 PDF 和 HTML 文件后将其删除,并将 PDF 保存到字节数组 Document 以节省服务器空间使用。 Writer 类和 pdf 字节数组没有删除方法。如果有人可以帮助我解决这个问题,我们将不胜感激。
// File output
Writer file = new FileWriter (new File("src/" + "xyz.html"));
template.process(data, file);
file.flush();
file.close();
HtmlConverter.convertToPdf(new FileInputStream("src/" + "xyz.html"),new FileOutputStream("src/" + "XYZ.pdf"));
Path pdfPath = Paths.get("src/" + "XYZ.pdf");
byte[] pdf = Files.readAllBytes(pdfPath);
byteDocument = pdf;
//Delete pdf and html files.
【问题讨论】:
-
您无需执行任何操作即可删除它们。如果您停止使用它们,垃圾收集器将摆脱它们。 Java 没有或不需要删除方法。