java读取world文档

说明:只支持world 2003 不支持2007 以及用WPS新建的world文档

package world;

import java.io.File;
import java.io.FileInputStream;

import org.textmining.text.extraction.WordExtractor;

public class WorldDemo {
	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;
		 }
		 /**
		  * @param args
		  */
		 public static void main(String[] args) {
		  // TODO Auto-generated method stub
		        try{
		         String text = WorldDemo.readDoc("D:\\3.doc");
		         System.out.println(text);
		        }catch(Exception ex){
		         ex.printStackTrace();
		        }
		 }
}


你可能感兴趣的:(java)