POIFSFileSystem java.io.IOException: Read error
使用POI解析word文档遇到java.io.IOException: Read error问题
jar包 poi-3.8.jar
private HWPFDocument getDocument() {
if(this.document == null) {
try {
this.document = new HWPFDocument(this.inputStream);
} catch (Exception var2) {
logger.error("open failed!", var2);
throw new WordParserException("1");
}
}
return this.document;
}
HWPFDocument.class
public HWPFDocument(InputStream istream) throws IOException {
this(verifyAndBuildPOIFS(istream));
}
HWPFDocumentCore.class
public static POIFSFileSystem verifyAndBuildPOIFS(InputStream istream) throws IOException {
PushbackInputStream pis = new PushbackInputStream(istream, 6);
byte[] first6 = new byte[6];
pis.read(first6);
if(first6[0] == 123 && first6[1] == 92 && first6[2] == 114 && first6[3] == 116 && first6[4] == 102) {
throw new IllegalArgumentException("The document is really a RTF file");
} else {
pis.unread(first6);
return new POIFSFileSystem(pis);
}
}
报错信息:
java.io.IOException: Read error
at java.io.FileInputStream.readBytes(Native Method)
at java.io.FileInputStream.read(FileInputStream.java:199)
at java.io.FilterInputStream.read(FilterInputStream.java:116)
at java.io.PushbackInputStream.read(PushbackInputStream.java:169)
at java.io.FilterInputStream.read(FilterInputStream.java:90)
at org.apache.poi.hwpf.HWPFDocumentCore.verifyAndBuildPOIFS(HWPFDocumentCore.java:95)
at org.apache.poi.hwpf.HWPFDocument.<init>(HWPFDocument.java:174)
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
