java读取word文件的内容
publicstaticvoidmain(String[]args){try{Stringtext=readDoc("E:///sw.doc");System.out.p...
public static void main(String[] args) {
try {
String text = readDoc("E:///sw.doc");
System.out.println(text);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static String readDoc(String doc) throws Exception {
// 创建输入流读取doc文件
FileInputStream in = new FileInputStream(doc);
WordExtractor extractor = new WordExtractor();
System.out.println("sadasdas");
String text = extractor.extractText(in);
return text;
}
报错
sadasdas
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.poi.poifs.filesystem.POIFSFileSystem.getRoot()Lorg/apache/poi/poifs/filesystem/DirectoryEntry;
at org.textmining.text.extraction.WordExtractor.extractText(WordExtractor.java:51)
at favorite.FileStreamOperate.readDoc(FileStreamOperate.java:41)
at favorite.FileStreamOperate.main(FileStreamOperate.java:29) 展开
try {
String text = readDoc("E:///sw.doc");
System.out.println(text);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static String readDoc(String doc) throws Exception {
// 创建输入流读取doc文件
FileInputStream in = new FileInputStream(doc);
WordExtractor extractor = new WordExtractor();
System.out.println("sadasdas");
String text = extractor.extractText(in);
return text;
}
报错
sadasdas
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.poi.poifs.filesystem.POIFSFileSystem.getRoot()Lorg/apache/poi/poifs/filesystem/DirectoryEntry;
at org.textmining.text.extraction.WordExtractor.extractText(WordExtractor.java:51)
at favorite.FileStreamOperate.readDoc(FileStreamOperate.java:41)
at favorite.FileStreamOperate.main(FileStreamOperate.java:29) 展开
展开全部
WordExtractor的用法错了,你用下面的方法试试:
......
File file = new File(doc);
FileInputStream fileInputStream = getFileInputStream(file);
WordExtractor wordExtractor = new WordExtractor(fileInputStream);
String text = wordExtractor.getText();
......
......
File file = new File(doc);
FileInputStream fileInputStream = getFileInputStream(file);
WordExtractor wordExtractor = new WordExtractor(fileInputStream);
String text = wordExtractor.getText();
......
更多追问追答
追问
getFileInputStream(file)是什么 报错啊?下面的3个步骤都报错了
追答
FileInputStream fileInputStream = new FileInputStream(file);你在试试
展开全部
没有引jar 或者 jar冲突
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2012-09-20
展开全部
没有导入poi相应的jar包,所以找不到相应的方法
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
把全部代码贴出来,瞧瞧
追问
这个就是了 除了类名 都有了
追答
应该是你WordkExtractor这个类出了问题,你debug一下就知道了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |