lucene-使用lius解析pdf、ppt、rtf、txt、xml

1、代码

package liusextract;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.UnsupportedEncodingException;

import lius.index.pdf.PdfIndexer;
import lius.index.powerpoint.PPTIndexer;
import lius.index.rtf.RTFIndexer;
import lius.index.txt.TXTIndexer;
import lius.index.xml.XmlFileIndexer;


public class pptandpdftest {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//pdf
PdfIndexer pi=new PdfIndexer();
File f=new File("./htmls/readme.pdf");
try {
pi.setStreamToIndex(new FileInputStream(f));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String text1=pi.getContent().substring(0, 200);
System.out.println("pdf:"+text1);
//ppt
PPTIndexer ppi=new PPTIndexer();
f=new File("./htmls/123.ppt");
try {
ppi.setStreamToIndex(new FileInputStream(f));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String text2=ppi.getContent().substring(0, 200);
System.out.println("ppt:"+text2);
//rtf
RTFIndexer rti=new RTFIndexer();
f=new File("./htmls/111.rtf");
try {
rti.setStreamToIndex(new FileInputStream(f));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String text3=rti.getContent();
try {
text3=new String(text3.getBytes("ISO-8859-1"));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("rtf:"+text3);
//txt
TXTIndexer ti=new TXTIndexer();
f=new File("./htmls/readme.txt");
try {
ti.setStreamToIndex(new FileInputStream(f));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String text4=ti.getContent().substring(0, 200);
System.out.println("txt:"+text4);
//xml
XmlFileIndexer xmli=new XmlFileIndexer();
f=new File("./htmls/cd_catalog.xml");
try {
xmli.setStreamToIndex(new FileInputStream(f));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String text5=xmli.getContent();
try {
text5=new String(text5.getBytes("ISO-8859-1"));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("xml:"+text5);

}

}
2、效果

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值