下载lius
http://sourceforge.net/projects/lius/
1、解析word
package liusextract;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import lius.index.msword.WordIndexer;
public class wordtest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
WordIndexer wi=new WordIndexer();
File f=new File("./htmls/ddd.doc");
try {
wi.setStreamToIndex(new FileInputStream(f));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String text=wi.getContent();
System.out.print(text);
}
}
效果

2、excel
package liusextract;
import lius.index.excel.ExcelIndexer;
import java.io.*;
public class exceltest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
ExcelIndexer ei=new ExcelIndexer();
File f=new File("./htmls/book1.xls");
try {
ei.setStreamToIndex(new FileInputStream(f));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String text=ei.getContent();
System.out.print(text);
}
}
本文介绍了一个名为LIUS的文档解析库,并通过两个示例演示了如何使用该库解析Word和Excel文件,包括导入必要的包、创建文件输入流、获取文件内容并打印出来等步骤。
1679

被折叠的 条评论
为什么被折叠?



