用JAVA 怎样才能把word文件读取出来 显示在页面上
网上的例子看了很多 好多都没用
package org.zhou.testFileRW;
/*****显示Word中的内容*******/
import java.io.FileInputStream;
import org.apache.poi.hwpf.extractor.WordExtractor;
public class SeedWork {
public SeedWork() {
}
public static void main(String args[]) throws Exception {
FileInputStream in = new FileInputStream("d:\\aa.doc ");
WordExtractor extractor = new WordExtractor(in);
String str = extractor.getText();
System.out.println("the result is: " + str);
}
}
我下的POI 3.7 .jar 里没如下包
import org.apache.poi.hwpf.extractor.WordExtractor;
扩展包里
tm-extractors-0.4.jar
用的是
import org.textmining.text.extraction.WordExtractor;
按网找的写了下面这段代码 结构运行时报异常:
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)
package org.zhou.testFileRW;
import java.io.File;
import java.io.FileInputStream;
import org.textmining.text.extraction.WordExtractor;
public class WordReader {
public static String readDoc(String doc) throws Exception {
// 创建输入流读取DOC文件
FileInputStream in = new FileInputStream(new File(doc));
WordExtractor extractor = null;
String text = null;
// 创建WordExtractor
extractor = new WordExtractor();
// 对DOC文件进行提取
text = extractor.extractText(in);
return text;
}
public static void main(String[] args) {
try {
String text = WordReader.readDoc("E:\\other\\00.doc");
System.out.println(text);
} catch (Exception e) {
e.printStackTrace();
}
}
}
不知道什么情况 包都在 方法也有 就是读不了
那个发发成功的例子看下
如果word里面有图片怎么办。你考虑过没?如果和睁态是单纯的文字,那么很简单。不需要第三方jar包,直早仿接文件字符流来读取,你是在ide里面开发还唤源是用ant编译的,孽jar包安装的claaspath中去了
靠,这么复杂?没时间看哦。O(∩_∩)O哈哈~。。
拿分来吧!!!!!!!!!!!!!
可以使用Scanner这个类完成,你去了解下这个类吧
WORD的编码方式不是公开的,你提取的内容里肯定有很多的乱码,EXCEL和TXT文件内容提取无乱码