import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import org.apache.poi.hwpf.extractor.WordExtractor;
public class StreamDemo_17 {
/**
* @param 用POI读取word文件中的内容
*/
public static void main(String[] args) {
StreamDemo_17 s = new StreamDemo_17();
String path = "C:\\fileText.doc";
try {
s.readDocFile(path);
} catch (IOException e) {
System.out.println("读取失败:" + path + "文件不存在" + e.getMessage());
}
}
public void readDocFile(String origFileName) throws IOException {
System.out.println("C:\\fileText.doc中的内容如下:\n");
// 创建文件输入流
FileInputStream in = new FileInputStream(new File(origFileName));
WordExtractor extractor = null;
String text = null;
// 创建WordExtractor
extractor = new WordExtractor(in);
// 对DOC文件进行提取
text = extractor.getText();
System.out.println(text);
}
}
import java.io.FileInputStream;
import java.io.IOException;
import org.apache.poi.hwpf.extractor.WordExtractor;
public class StreamDemo_17 {
/**
* @param 用POI读取word文件中的内容
*/
public static void main(String[] args) {
StreamDemo_17 s = new StreamDemo_17();
String path = "C:\\fileText.doc";
try {
s.readDocFile(path);
} catch (IOException e) {
System.out.println("读取失败:" + path + "文件不存在" + e.getMessage());
}
}
public void readDocFile(String origFileName) throws IOException {
System.out.println("C:\\fileText.doc中的内容如下:\n");
// 创建文件输入流
FileInputStream in = new FileInputStream(new File(origFileName));
WordExtractor extractor = null;
String text = null;
// 创建WordExtractor
extractor = new WordExtractor(in);
// 对DOC文件进行提取
text = extractor.getText();
System.out.println(text);
}
}