我正在使用 Apache tika 解析一个包含 RTF 内容的文档,但它给出了一些例外。它没有给出文件的内容。
这是一段代码:
public String contentEx(File f) throws IOException, SAXException,
TikaException {
System.out.println(f.getName());
InputStream is = new FileInputStream(f);
Parser ps = new AutoDetectParser();
BodyContentHandler bch = new BodyContentHandler();
Metadata metadata = new Metadata();
ps.parse(is, bch, metadata, new ParseContext());
return bch.toString();
}
但是当我这样调用这个方法时:
public static void main(String[] args) throws IOException, SAXException,
TikaException {
StanfrdEntityExtr see = new StanfrdEntityExtr()
File Resum_F = new File("/home/rahul/Documents/resumes/212/swetank.docx");
String s1 = see.contentEx(Resum_F);
}
它给出了例外:
Exception in thread "main" org.apache.tika.exception.TikaException: Unexpected RuntimeException from org.apache.tika.parser.rtf.RTFParser@39614c6
at org.apache.tika.parser.CompositeParser.parse(CompositeParser.java:244)
at org.apache.tika.parser.CompositeParser.parse(CompositeParser.java:242)
at org.apache.tika.parser.AutoDetectParser.parse(AutoDetectParser.java:120)
at stranfordParse.StanfrdEntityExtr.contentEx(StanfrdEntityExtr.java:92)
at stranfordParse.StanfrdEntityExtr.main(StanfrdEntityExtr.java:50)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 9
at org.apache.tika.parser.rtf.TextExtractor.processControlWord(TextExtractor.java:872)
at org.apache.tika.parser.rtf.TextExtractor.parseControlWord(TextExtractor.java:566)
at org.apache.tika.parser.rtf.TextExtractor.parseControlToken(TextExtractor.java:492)
at org.apache.tika.parser.rtf.TextExtractor.extract(TextExtractor.java:459)
at org.apache.tika.parser.rtf.TextExtractor.extract(TextExtractor.java:448)
at org.apache.tika.parser.rtf.RTFParser.parse(RTFParser.java:56)
at org.apache.tika.parser.CompositeParser.parse(CompositeParser.java:242)
... 4 more
如何解决这个异常?如何使用 apache Tika 正确打印此文档的内容?我找到了一些解决方案,但它们不起作用。
给我一些想法!任何帮助将不胜感激!