实例化对象NPOIFSFileSystem使用文件的问题 [英] Issues instantiating NPOIFSFileSystem Object with File

查看:7764
本文介绍了实例化对象NPOIFSFileSystem使用文件的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

First up I am asking this question from home =- away from all the source; I will attempt to update tomorrow.

从本质上讲,我实例化NPOIFSFileSystem像这样:

Essentially I am instantiating NPOIFSFileSystem like so:

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

该getLocalFile()方法返回一个字符串文件路径 - 我知道文件在该位置存在。然而,instatiation返回错误:

The getLocalFile() method returns a String to a file path - I know the file exists in that location. However, the instatiation is returning an error:

ArrayIndexOutOfBounds

有没有人有任何想法在这呢?

Does anyone have any ideas on this at all?

问题中的文件是一个XLS文件,它不包含阿拉伯语字符,我不知道这是否会导致问题。

The file in question is an XLS file, it does contain Arabic characters and I wonder if that could cause the problem.

我没previously有这个使用POIFSFileSystem,但有问题的XLS文件引起了一些问题和各种论坛建议迁移到NPOIFSFileSystem

I did previously have this using POIFSFileSystem but the XLS file in question caused some issues and various forums recommended moving to NPOIFSFileSystem

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

So, has anyone seen this before? Or can anyone offer me some tips/pointers on this please?

如果只是问及明天,当我回来工作(我们有固定我们的互联网连接),我会更新这个问题,需要进一步明晰

If any further clarity is needed just ask and tomorrow, when I'm back at work (and we have fixed our internet connection) I will update this question.

在此先感谢
内森

Thanks in advance Nathan

修改1
以下是完整的堆栈跟踪:

EDIT 1 Here is the full stack trace:

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

I am running POI3-8

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

I will upgrade to 3.9 and try again and let you know.

谢谢
内森

编辑2

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

I have updated to 3.9 and will test again soon - just waiting for some other items to complete prior to testing. I will post back the results.

谢谢
内森

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

EDIT 3 Same odd problem. Here is the stack trace now I'm using 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)

谢谢
内森

Thanks Nathan

修改4
我从NPOIFSFileSystem切换到POIFSFileSystem:

EDIT 4 I have switched from NPOIFSFileSystem to POIFSFileSystem:

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

这给我下面的堆栈跟踪:

This give me the following stack trace:

    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文件。

I know the file exists and is a valid XLS file.

我使用Java 1.7和POI 3.9。

I am using Java 1.7 and Poi 3.9.

该应用程序是从/ usr / JAVA / data_map_tool运行,文件下载,并从加工的/ home / javaapp / data_map_files

The application is running from /usr/java/data_map_tool and the files are downloaded to and processed from /home/javaapp/data_map_files

应用程序谁是有问题的目录的所有者javaapp用户下运行。

The application runs under the javaapp user who is the owner of the directories in question.

在一个点上,我有应用程序运行在目录中下载到一个目录中的文件和工作 - 但是,文件大小禁止要去使用,作为一个文件存储

At one point I had the files downloaded to a directory within the directory the application is running under and that worked - however, the file size prohibits on going use of that as a the file store.

有没有人有任何想法在这,因为我撞我的头靠在墙上与此有关。

Does anyone have any ideas on this as I am banging my head against the wall with this.

推荐答案

好了,我已经破解了!如所建议的问题是与原始源文件。为了削减长话短说是BOM。有一个字节顺序标记的XSL文件的开始。当我的Java应用程序打开这种带有一个FileInputStream它会导致混乱。

Well, I've cracked it! As suggested the issue was with the original source file. To cut a long story short it was BOM. There was a Byte Order Marker at the start of the XSL file. When my Java application opens this with a FileInputStream it causes chaos.

所以,我刚刚更新了我的code来打开文件

So, I just updated my code to open the file with

BOMInputStream();

来自Apache公地IO。

from Apache commons io.

这已经解决了这个问题。

This has resolved the issue.

非常感谢
内森

Many thanks Nathan

这篇关于实例化对象NPOIFSFileSystem使用文件的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆