gpt4 book ai didi

java - 无法读取整个 header ;读取 0 字节;预计 512 字节

转载 作者:行者123 更新时间:2023-12-02 13:00:36 25 4
gpt4 key购买 nike

我使用 Apache poi 3.8 来读取 xls 文件,但出现异常:

        java.io.IOException: Unable to read entire header; 0 bytes read; expected 512 bytes
at org.apache.poi.poifs.storage.HeaderBlock.alertShortRead(HeaderBlock.java:226)
at org.apache.poi.poifs.storage.HeaderBlock.readFirst512(HeaderBlock.java:207)
at org.apache.poi.poifs.storage.HeaderBlock.<init>(HeaderBlock.java:104)
at org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:138)

使用的代码示例:

     FileInputStream myInput = new FileInputStream(excelFilePathWithExtension);
logger.debug("FileInputStream::"+myInput);

POIFSFileSystem myFileSystem = new POIFSFileSystem(myInput);
logger.debug("POIFSFileSystem::"+myFileSystem);

Workbook workbook = WorkbookFactory.create(myFileSystem);

请帮帮我?

最佳答案

如果我们看一下 HeaderBlocks 类,我们可以看到这些 block :

public HeaderBlock(InputStream stream) throws IOException {
// Grab the first 512 bytes
// (For 4096 sized blocks, the remaining 3584 bytes are zero)
// Then, process the contents
this(readFirst512(stream));
...
}

您使用的构造函数将读取输入流的前 512 个字节,然后调用私有(private)构造函数。

如果没有足够的字节可供读取,则 readFirst512 方法会抛出异常。

此外,POI's document假设 POI 文件系统结构以 512 字节的 header block 开始。

所以...看来您的文件对于 POI 来说不够大。

关于java - 无法读取整个 header ;读取 0 字节;预计 512 字节,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12616689/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com