源文档:
给哈弗大狗.docx (24.5 KB)
代码:
MultipartFile file ;
Document document = AsposeDocTypeConvert.getDocument(file);
try {
document.save("D:\\Users\\00306664.WIN-72KKI8CSIBD\\Desktop\\实例文档\\aa.docx");
} catch (Exception e) {
throw new RuntimeException(e);
}
public static Document getDocument(MultipartFile file) {
if (Objects.isNull(file)) {
throw new BusinessException("param file can not be null");
}
try {
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(file.getBytes());
Document document = new Document(byteArrayInputStream);
byteArrayInputStream.close();
return document;
} catch (Exception e) {
log.error("文档类型转换失败,原因:" + e.getMessage());
throw new BusinessException(e.getMessage());
}
}
最终的文档:
aa.docx (19.6 KB)
丢失的内容: