POIFSFileSystem java.io.IOException: Read error

本文介绍了解析Word文档时遇到的java.io.IOException: Read error问题及其堆栈跟踪信息。使用Apache POI库版本3.8尝试读取Word文档(.doc)过程中出现错误,问题可能源于文件输入流读取失败。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用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)




评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值