java.lang.IllegalArgumentException: Your InputStream was neither an OLE2 stream, nor an OOXML stream

异常信息:
java.lang.IllegalArgumentException: Your InputStream was neither an OLE2 stream, nor an OOXML stream
    at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:75)
    at com.eshore.framework.utils.html2word.HtmlDelUtil.resolveOnlyTextKlp(HtmlDelUtil.java:229)
    at com.eshore.framework.utils.html2word.HtmlDelUtil.main(HtmlDelUtil.java:280)

在创建Workbook时使用HSSFWork读取xls文件后缀时出现过,切换为WorkbookFactory.creat(new FileInputStream("xx"));
异常信息:
Unable to read entire header; 0 bytes read; expected 512 bytes 

方法代码如下:

private static void resolveOnlyTextKlp(){
    String localFilePath = "E:\\extractKlp\\bak\\onlyTextKlp.xlsx";
    int circleNum = 10;
    int excelIndex = 1;
    FileInputStream input = null;
    FileOutputStream output = null;
    try {
        input = new FileInputStream(new File(localFilePath));
        output = new FileOutputStream(new File(localFilePath));
        
        Workbook workbook = WorkbookFactory.create(input);
        Sheet klpSheet = workbook.getSheetAt(0);
        
        for(int i=0;i

在上面我同时创建输入输入流就会出现该错误Your InputStream was neither an OLE2 stream, nor an OOXML stream
解决办法:
    将上面的output注释打开下面的output;即不在创建Workbook之前创建多个对同一个文件处理的流对象。
    有错请指正,一同学习进步!

你可能感兴趣的:(Java)