diff --git a/src/main/java/com/alibaba/excel/context/WriteContextImpl.java b/src/main/java/com/alibaba/excel/context/WriteContextImpl.java index c1f89f02..5b4efb18 100644 --- a/src/main/java/com/alibaba/excel/context/WriteContextImpl.java +++ b/src/main/java/com/alibaba/excel/context/WriteContextImpl.java @@ -488,14 +488,18 @@ public class WriteContextImpl implements WriteContext { Encryptor encryptor = new EncryptionInfo(EncryptionMode.standard).getEncryptor(); encryptor.confirmPassword(writeWorkbookHolder.getPassword()); OPCPackage opcPackage = null; + OutputStream outputStream = null; try { opcPackage = OPCPackage.open(file, PackageAccess.READ_WRITE); - OutputStream outputStream = encryptor.getDataStream(fileSystem); + outputStream = encryptor.getDataStream(fileSystem); opcPackage.save(outputStream); } finally { if (opcPackage != null) { opcPackage.close(); } + if (outputStream != null) { + outputStream.close(); + } } return fileSystem; }