Я использую утилиту apache poi (poi-scratchpad-3.9.jar и связанную версию 3.9 POI jar) для преобразования файла документа в txt. Он работает с большинством файлов, но я получаю исключение, как показано ниже.
java.lang.IndexOutOfBoundsException: 0 not accessible in a list of length 0
at org.apache.poi.util.IntList.get(IntList.java:346)
at org.apache.poi.poifs.storage.BlockAllocationTableReader.fetchBlocks(BlockAllocationTableReader.java:224)
at org.apache.poi.poifs.storage.BlockListImpl.fetchBlocks(BlockListImpl.java:123)
at org.apache.poi.poifs.storage.SmallDocumentBlockList.fetchBlocks(SmallDocumentBlockList.java:30)
at org.apache.poi.poifs.filesystem.POIFSFileSystem.processProperties(POIFSFileSystem.java:521)
at org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:163)
at org.apache.poi.hwpf.HWPFDocumentCore.verifyAndBuildPOIFS(HWPFDocumentCore.java:106)
at org.apache.poi.hwpf.HWPFDocument.<init>(HWPFDocument.java:174)
Кодекс следующий
fileInputStream = new FileInputStream(file.getAbsolutePath());
// A HWPFDocument used to read document file from FileInputStream
HWPFDocument doc = new HWPFDocument(fileInputStream);
// A WordExtractor used to read textual content from document
WordExtractor docExtractor = new WordExtractor(doc);
// This Array stores each line from the document file.
String[] docArray = docExtractor.getParagraphText();
StringBuilder contents = new StringBuilder();
for (int i = 0; i < docArray.length; i++) {
if (docArray[i] != null) {
contents.append(docArray[i]);
contents.append(System.getProperty("line.separator"));
}
}
isConverted = FileDirectoryOperations.writeTextOutputFile(targetFilePath, contents.toString());
мы получаем исключение в строке HWPFDocument doc = new HWPFDocument(fileInputStream);
есть ли у нас какое-либо исправление для этого.
пожалуйста, поделитесь своими комментариями.
Заранее спасибо.
Сурабх