使用用POI導出文件時拋出異常java.io.IOException: Broken pipe
ERROR: 'java.io.IOException: Broken pipe' org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException: Fail to save: an error occurs while saving the package : The part /docProps/core.xml fail to be saved in the stream with marshaller org.apache.poi.openxml4j.opc.internal.marshallers.ZipPackagePropertiesMarshaller@783e76d
原因:輸入流,輸出流在使用之后(輸入流用於構造函數,輸出流用於寫入數據),再使用同樣的流做之前的事會報錯(再使用輸入流報錯流為空,再使用輸出流報錯為 org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException: Fail to save: an error occurs while saving the package : The part /docProps/app.xml failed to be saved in the stream with marshaller org.apache.poi.openxml4j.opc.internal.marshallers.DefaultMarshaller@4bbfb90a)。所以對於同一個引用的流,在使用之后還想要繼續使用的話,必須重新新建一個流對象
記得使用只用及時關閉 流。為了避免在特殊情況下導致流關閉失敗,應該吧關閉流的操作放在finally代碼塊中
}finally { inputStream.close(); ouputStream.close(); workbook.close(); }