poi读取通过xml方式修改过的docx出错。

我通过zip4j解压docx文件,修改里面的ducomen.xml来改变docx的内容。当我重新把改完的文件经行压缩后,POI读取docx文件时报错:
Exception in thread "main" java.io.IOException: Failed to read zip entry source
at org.apache.poi.openxml4j.opc.ZipPackage.(ZipPackage.java:103)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:324)
at org.apache.poi.util.PackageHelper.open(PackageHelper.java:37)
at org.apache.poi.xwpf.usermodel.XWPFDocument.(XWPFDocument.java:116)
at test.Test1.test(Test1.java:36)
at test.Test1.main(Test1.java:29)
Caused by: java.util.zip.ZipException: only DEFLATED entries can have EXT descriptor
at java.util.zip.ZipInputStream.readLOC(ZipInputStream.java:310)
at java.util.zip.ZipInputStream.getNextEntry(ZipInputStream.java:122)
at org.apache.poi.openxml4j.util.ZipSecureFile$ThresholdInputStream.getNextEntry(ZipSecureFile.java:280)
at org.apache.poi.openxml4j.util.ZipInputStreamZipEntrySource.(ZipInputStreamZipEntrySource.java:52)
at org.apache.poi.openxml4j.opc.ZipPackage.(ZipPackage.java:100)
... 5 more

** zip4j的压缩代码:**

         ZipFile zipFile = new ZipFile(zipPath);

        ZipParameters parameters = new ZipParameters();
        parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
        parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
        parameters.setIncludeRootFolder(false);

        zipFile.addFolder(dirPath, parameters);

读取docx的代码:

         XWPFWordExtractor extractor = new XWPFWordExtractor(new XWPFDocument(new FileInputStream(new File(f))));
        System.out.println(extractor.getText());

f为文件路径

我通过WPS打开这个docx是没问题的,但是使用POI来读取的就会报错,错误信息是在看不懂不知道有大佬知道吗?

2个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐