java poi 读取word 报错 java.lang.ArrayIndexOutOfBoundsException 希望能帮助一下
我的源码:publicstaticvoidmain(String[]args){FileInputStreamfis=null;Stringtext;try{fis=ne...
我的源码:
public static void main(String[] args) {
FileInputStream fis = null;
String text;
try {
fis = new FileInputStream("files\\aa.doc");
POITextExtractor extractor = ExtractorFactory.createExtractor(fis);
text = extractor.getText();
System.out.println(text);
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
报的错误
java.lang.ArrayIndexOutOfBoundsException
at java.lang.System.arraycopy(Native Method)
at org.apache.poi.hwpf.model.StyleDescription.<init>(StyleDescription.java:122)
at org.apache.poi.hwpf.model.StyleSheet.<init>(StyleSheet.java:105)
at org.apache.poi.hwpf.HWPFDocument.<init>(HWPFDocument.java:261)
at org.apache.poi.hwpf.extractor.WordExtractor.<init>(WordExtractor.java:64)
at org.apache.poi.extractor.ExtractorFactory.createExtractor(ExtractorFactory.java:124)
at org.apache.poi.extractor.ExtractorFactory.createExtractor(ExtractorFactory.java:112)
at org.apache.poi.extractor.ExtractorFactory.createExtractor(ExtractorFactory.java:83)
at Test.main(Test.java:62) 展开
public static void main(String[] args) {
FileInputStream fis = null;
String text;
try {
fis = new FileInputStream("files\\aa.doc");
POITextExtractor extractor = ExtractorFactory.createExtractor(fis);
text = extractor.getText();
System.out.println(text);
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
报的错误
java.lang.ArrayIndexOutOfBoundsException
at java.lang.System.arraycopy(Native Method)
at org.apache.poi.hwpf.model.StyleDescription.<init>(StyleDescription.java:122)
at org.apache.poi.hwpf.model.StyleSheet.<init>(StyleSheet.java:105)
at org.apache.poi.hwpf.HWPFDocument.<init>(HWPFDocument.java:261)
at org.apache.poi.hwpf.extractor.WordExtractor.<init>(WordExtractor.java:64)
at org.apache.poi.extractor.ExtractorFactory.createExtractor(ExtractorFactory.java:124)
at org.apache.poi.extractor.ExtractorFactory.createExtractor(ExtractorFactory.java:112)
at org.apache.poi.extractor.ExtractorFactory.createExtractor(ExtractorFactory.java:83)
at Test.main(Test.java:62) 展开
2个回答
追问
对的。换个文档就可以。。。
那按你的意思这个没有办法通用了。。。我是想对别人拿过来的所有文档都能读取的
追答
你这样 试试
WordExtractor extractor = new WordExtractor(POIXMLDocument.openPackage("D:\\bb.doc"));
text = extractor.getText();
或者
HWPFDocument hdt = new HWPFDocument(fis);
Range range = hdt.getRange();
System.out.println(range.text());
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询