使用TextMiniing和Apache POI获得Word文件内容,无须MS-Office ActiveX
2005-07-25 11:12
615 查看
/*
* Created on 2005/07/18
* 使用tm-extractors-0.4.jar
*/
package com.nova.colimas.common.doc;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import org.textmining.text.extraction.WordExtractor;/**
* Deal with ms-word 2000/xp files.
* @author tyrone
*
*/
public class WordProcess extends DocProcess {
public static String run(String filename){
WordExtractor extractor=null;
String text=null;
try{
FileInputStream in = new FileInputStream (filename);
extractor = new WordExtractor();
text=extractor.extractText(in);
}catch(Exception ex){
//log
return null;
}
return text;
}
public static void main(String[] args){
try{
FileOutputStream out=new FileOutputStream("result.txt");
out.write(WordProcess.run(args[0]).getBytes());
out.flush();
out.close();
}catch(Exception ex){
System.out.println(ex.toString());
}
}
}
* Created on 2005/07/18
* 使用tm-extractors-0.4.jar
*/
package com.nova.colimas.common.doc;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import org.textmining.text.extraction.WordExtractor;/**
* Deal with ms-word 2000/xp files.
* @author tyrone
*
*/
public class WordProcess extends DocProcess {
public static String run(String filename){
WordExtractor extractor=null;
String text=null;
try{
FileInputStream in = new FileInputStream (filename);
extractor = new WordExtractor();
text=extractor.extractText(in);
}catch(Exception ex){
//log
return null;
}
return text;
}
public static void main(String[] args){
try{
FileOutputStream out=new FileOutputStream("result.txt");
out.write(WordProcess.run(args[0]).getBytes());
out.flush();
out.close();
}catch(Exception ex){
System.out.println(ex.toString());
}
}
}
相关文章推荐
- 使用Apache POI和Java获得Excel文件内容,无须MS-Office ActiveX OLE
- 使用Apache POI和Java获得Excel文件内容,无须MS-Office ActiveX OLE
- Java中使用Apache POI读取word文件简单示例
- 使用Properties去读取配置文件,并获得具体内容值
- 使用Activex插件复制剪贴板中的word或excel内容到web HTML编辑器并自动上传图片或文件
- C#遍历文件读取Word内容以及使用BackgroundWorker对象打造平滑进度条
- 使用ifstream和getline读取文件内容[c++]
- 【Android】使用Gradle打包时,获取svn的版本号,删除unalign.apk文件,获得版本号,并设定在打包的文件名称中
- 使用Perl 修改多个类似文件的内容, 更新大量文件
- 获得Properties文件的内容
- java 使用IO流读取指定文件中的内容
- 使用Java读取Excel文件内容
- 使用Apache POI生成指定格式的Excel文件
- 使用POI读写word docx文件
- 使用POI读取excel文件内容
- 封装数据库的连接的方法(用Properties类获得文件里面相应的内容)
- 关于使用jQuery - 获得内容和属性的心得
- word转换为pdf 创建临时文件时出现错误:Word未能写某些嵌入对象,因为内容或磁盘空间不足
- 我使用过的Linux命令之sync - 强制将内存中的文件缓冲内容写到磁盘
- 使用Jacob与Word文件交互