0

首先,我在家里问这个问题=-远离所有来源;我明天会尝试更新。

本质上我是像这样实例化 NPOIFSFileSystem :

NPOIFSFileSystem fs = new NPOIFSFileSystem(new File(this.getLocalFile()));

getLocalFile() 方法将字符串返回到文件路径 - 我知道该文件存在于该位置。但是,实例化返回错误:

ArrayIndexOutOfBounds

有没有人对此有任何想法?

有问题的文件是一个 XLS 文件,它确实包含阿拉伯字符,我想知道这是否会导致问题。

我以前确实使用过 POIFSFileSystem ,但有问题的 XLS 文件引起了一些问题,各种论坛建议移至 NPOIFSFileSystem

那么,有没有人见过这个?或者任何人都可以给我一些提示/指针吗?

如果需要进一步澄清,请询问,明天当我回来工作时(我们已经修复了我们的互联网连接),我会更新这个问题。

在此先感谢内森

编辑 1 这是完整的堆栈跟踪:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
    at org.apache.poi.poifs.filesystem.BlockStore$ChainLoopDetector.claim(BlockStore.java:95)
    at org.apache.poi.poifs.filesystem.NPOIFSStream$StreamBlockByteBufferIterator.next(NPOIFSStream.java:212)
    at org.apache.poi.poifs.filesystem.NPOIFSStream$StreamBlockByteBufferIterator.next(NPOIFSStream.java:186)
    at org.apache.poi.poifs.property.NPropertyTable.buildProperties(NPropertyTable.java:88)
    at org.apache.poi.poifs.property.NPropertyTable.<init>(NPropertyTable.java:66)
    at org.apache.poi.poifs.filesystem.NPOIFSFileSystem.readCoreContents(NPOIFSFileSystem.java:379)
    at org.apache.poi.poifs.filesystem.NPOIFSFileSystem.<init>(NPOIFSFileSystem.java:202)
    at org.apache.poi.poifs.filesystem.NPOIFSFileSystem.<init>(NPOIFSFileSystem.java:163)
    at org.apache.poi.poifs.filesystem.NPOIFSFileSystem.<init>(NPOIFSFileSystem.java:145)
    at com.turnitin.datamap.parser.standard.XLSParser.defineParsableObject(XLSParser.java:67)
    at com.turnitin.datamap.parser.standard.XLSParser.setUp(XLSParser.java:56)
    at com.turnitin.datamap.parser.standard.XLSParser.<init>(XLSParser.java:46)
    at com.turnitin.datamap.controller.DataMapController.parseData(DataMapController.java:255)
    at com.turnitin.datamap.controller.DataMapController.processControl(DataMapController.java:162)
    at com.turnitin.datamap.controller.DataMapController.processStart(DataMapController.java:130)
    at com.turnitin.datamap.controller.DataMapController.main(DataMapController.java:61)

我正在运行 POI3-8

我将升级到 3.9,然后再试一次,让你知道。

再次感谢内森

编辑 2

我已经更新到 3.9 并将很快再次测试 - 只是在测试之前等待其他一些项目完成。我会发回结果。

谢谢内森

编辑 3 同样奇怪的问题。这是我现在使用 POI 3.9 的堆栈跟踪:

    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
    at org.apache.poi.poifs.filesystem.BlockStore$ChainLoopDetector.claim(BlockStore.java:95)
    at org.apache.poi.poifs.filesystem.NPOIFSStream$StreamBlockByteBufferIterator.next(NPOIFSStream.java:212)
    at org.apache.poi.poifs.filesystem.NPOIFSStream$StreamBlockByteBufferIterator.next(NPOIFSStream.java:186)
    at org.apache.poi.poifs.property.NPropertyTable.buildProperties(NPropertyTable.java:88)
    at org.apache.poi.poifs.property.NPropertyTable.<init>(NPropertyTable.java:66)
    at org.apache.poi.poifs.filesystem.NPOIFSFileSystem.readCoreContents(NPOIFSFileSystem.java:379)
    at org.apache.poi.poifs.filesystem.NPOIFSFileSystem.<init>(NPOIFSFileSystem.java:202)
    at org.apache.poi.poifs.filesystem.NPOIFSFileSystem.<init>(NPOIFSFileSystem.java:163)
    at org.apache.poi.poifs.filesystem.NPOIFSFileSystem.<init>(NPOIFSFileSystem.java:145)
    at com.turnitin.datamap.parser.standard.XLSParser.defineParsableObject(XLSParser.java:67)
    at com.turnitin.datamap.parser.standard.XLSParser.setUp(XLSParser.java:56)
    at com.turnitin.datamap.parser.standard.XLSParser.<init>(XLSParser.java:46)
    at com.turnitin.datamap.controller.DataMapController.parseData(DataMapController.java:264)
    at com.turnitin.datamap.controller.DataMapController.processControl(DataMapController.java:162)
    at com.turnitin.datamap.controller.DataMapController.processStart(DataMapController.java:130)
    at com.turnitin.datamap.controller.DataMapController.main(DataMapController.java:61)

谢谢内森

编辑 4 我已从 NPOIFSFileSystem 切换到 POIFSFileSystem:

FileInputStream fis = new FileInputStream(this.getFileToParse());
    POIFSFileSystem excelFile = new POIFSFileSystem(fis);
    Workbook wb = WorkbookFactory.create(excelFile);

这给了我以下堆栈跟踪:

    java.io.IOException: block[ 1273 ] already removed - does your POIFS have circular or duplicate block references?
    at org.apache.poi.poifs.storage.BlockListImpl.remove(BlockListImpl.java:89)
    at org.apache.poi.poifs.storage.RawDataBlockList.remove(RawDataBlockList.java:34)
    at org.apache.poi.poifs.storage.BlockAllocationTableReader.fetchBlocks(BlockAllocationTableReader.java:221)
    at org.apache.poi.poifs.storage.BlockListImpl.fetchBlocks(BlockListImpl.java:123)
    at org.apache.poi.poifs.storage.RawDataBlockList.fetchBlocks(RawDataBlockList.java:34)
    at org.apache.poi.poifs.property.PropertyTable.<init>(PropertyTable.java:63)
    at org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:159)
    at com.turnitin.datamap.parser.standard.XLSParser.defineParsableObject(XLSParser.java:68)
    at com.turnitin.datamap.parser.standard.XLSParser.setUp(XLSParser.java:56)
    at com.turnitin.datamap.parser.standard.XLSParser.<init>(XLSParser.java:46)
    at com.turnitin.datamap.controller.DataMapController.parseData(DataMapController.java:264)
    at com.turnitin.datamap.controller.DataMapController.processControl(DataMapController.java:162)
    at com.turnitin.datamap.controller.DataMapController.processStart(DataMapController.java:130)
    at com.turnitin.datamap.controller.DataMapController.main(DataMapController.java:61)

我知道该文件存在并且是有效的 XLS 文件。

我正在使用 Java 1.7 和 Poi 3.9。

应用程序从 /usr/java/data_map_tool 运行,文件从 /home/javaapp/data_map_files 下载并处理

该应用程序在作为相关目录所有者的 javaapp 用户下运行。

有一次,我将文件下载到了运行应用程序的目录中的一个目录中,并且该目录可以正常工作-但是,文件大小禁止将其用作文件存储。

有没有人对此有任何想法,因为我正用这个把头撞在墙上。

4

1 回答 1

0

嗯,我破解了!正如建议的那样,问题出在原始源文件上。长话短说就是BOM。XSL 文件的开头有一个字节顺序标记。当我的 Java 应用程序使用 FileInputStream 打开它时,它会导致混乱。

所以,我刚刚更新了我的代码以打开文件

BOMInputStream();

来自 Apache commons io。

这已经解决了这个问题。

非常感谢内森

于 2012-12-17T13:02:06.073 回答