### Question:
OFDDoc implements Closeable { public OFDDoc addAttachment(Attachment attachment) throws IOException { if (attachment == null) { return this; } DocDir docDefault = ofdDir.obtainDocDefault(); Path file = attachment.getFile(); docDefault.addResource(file); ST_Loc loc = docDefault.getRes().getAbsLoc() .cat(file.getFileName().toString()); double size = Files.size(file) / 1024d; CT_Attachment ctAttachment = attachment.getAttachment() .setID(String.valueOf(MaxUnitID.incrementAndGet())) .setCreationDate(LocalDate.now()) .setSize(size) .setFileLoc(loc); ResourceLocator rl = new ResourceLocator(ofdDir); Attachments attachments = obtainAttachments(docDefault, rl); cleanOldAttachment(rl, attachments, attachment.getName()); attachments.addAttachment(ctAttachment); return this; } OFDDoc(Path outPath);  OFDDoc(OFDReader reader, Path outPath); private  OFDDoc(); OFDDoc setDefaultPageLayout(PageLayout pageLayout); OFDDoc add(Div item); OFDDoc addVPage(VirtualPage virtualPage); AdditionVPage getAVPage(int pageNum); OFDDoc addAnnotation(int pageNum, Annotation annotation); PageLayout getPageLayout(); OFDDoc addAttachment(Attachment attachment); @Override void close();  }### Answer:
@Test void addAttachment() throws IOException { Path outP = Paths.get("target/AddAttachment.ofd"); Path file = Paths.get("src/test/resources", "eg_tulip.jpg"); Path file2 = Paths.get("src/test/resources", "NotoSerifCJKsc-Regular.otf"); try (OFDDoc ofdDoc = new OFDDoc(outP)) { Paragraph p = new Paragraph(); Span span = new Span("这是一个带有附件的OFD文件").setFontSize(10d); p.add(span); ofdDoc.add(p); ofdDoc.addAttachment(new Attachment("Gao", file)); ofdDoc.addAttachment(new Attachment("FontFile", file2)); } System.out.println("生成文档位置：" + outP.toAbsolutePath().toString()); }
@Test void replaceAttachment() throws IOException { Path srcP = Paths.get("src/test/resources/AddAttachment.ofd"); Path outP = Paths.get("target/ReplaceAttachment.ofd"); Path file = Paths.get("src/test/resources", "ASCII字体宽度测量.html"); try (OFDReader reader = new OFDReader(srcP); OFDDoc ofdDoc = new OFDDoc(reader, outP)) { ofdDoc.addAttachment(new Attachment("Gao", file)); } System.out.println("生成文档位置：" + outP.toAbsolutePath().toString()); }