欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

lucene入门-解析word文档

程序员文章站 2022-05-16 09:33:42
...

下载:

http://mirrors.ibiblio.org/pub/mirrors/maven2/org/textmining/tm-extractors/0.4/

java代码如下:

package extract;

import java.io.*;
import org.textmining.text.extraction.WordExtractor;


public class ExtractorWord {

/**
* @param args
*/
public static String getText(String file){
String s="";
String wordfile=file;
WordExtractor extractor=null;
try {
FileInputStream in=new FileInputStream(new File(wordfile));
extractor=new WordExtractor();
s=extractor.extractText(in);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return s;
}
public static void toTextFile(String doc,String filename) throws Exception{
String s="";
String wordfile=doc;
String txtfile=filename;
WordExtractor extractor=null;
try {
s=getText(wordfile);
PrintWriter pw=new PrintWriter(new FileWriter(new File(filename)));
pw.write(s);
pw.flush();
pw.close();
System.out.print("成功写入文件!");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
String sc=getText("D:/workspace/testsearch2/htmls/ddd.doc");
System.out.print(sc);
toTextFile("D:/workspace/testsearch2/htmls/ddd.doc","D:/workspace/testsearch2/htmls/ddd.txt");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}
效果如下:

相关标签: lucene