Apache tika -- 解析多种类型(word、pdf、txt 等)文件!
来源:互联网 发布:淘宝摩托车怎么样 编辑:程序博客网 时间:2024/06/05 14:46
apache 是个伟大的组织。
在lucene 检索 如火如荼时, apache不忘继续努力,近期提供了对各种格式文件进行解析的解决方案 -- apache旗下的tika. 虽然还没有1.0版 , 但已经很好用:
- /**
- * 解析各种类型文件
- * @param 文件路径
- * @return 文件内容字符串
- */
- public static String parse(String path) {
- String result = "";
- TikaConfig tikaConfig = TikaConfig.getDefaultConfig();
- try {
- result = ParseUtils.getStringContent(new File(path), tikaConfig);
- }catch (Exception e) {
- log.debug("[by ninja.hzw]" + e);
- }
- return result;
- }
很简单,可以解析各种文件,返回文档内容字符串, word2003/2007 、 pdf 、 txt 都经过测试,均能解析且无乱码问题。
oh, Great Apach
Tika 的下载和打包:
下载不用多说,google 一下“apache tika” 找到其官网下载即可。
- To build Tika from sources you first need to either download a source release or checkout the latest sources from version control.
- Once you have the sources, you can build them using the Maven 2 build system. Executing the following command in the base directory will build the sources and install the resulting artifacts in your local Maven repository.
- mvn install
apache 已经说得很清楚,进入下载后的tika 目录 ,然后执行maven install 即可。(当然这里需要您懂得maven2的使用。当然不会的朋友可以联系我^^ . 还需注意,必须为jdk1.5 + 才能成功编译打包。)
打包完后产生以下 jar:
- tika-core/target/tika-core-0.7.jar
- Tika core library. Contains the core interfaces and classes of Tika, but none of the parser implementations. Depends only on Java5.
- tika-parsers/target/tika-parsers-0.7.jar
- Tika parsers. Collection of classes that implement the Tika Parser interface based on various external parser libraries.
- tika-app/target/tika-app-0.7.jar
- Tika application. Combines the above libraries and all the external parser libraries into a single runnable jar with a GUI and a command lineinterface.
- tika-bundle/target/tika-bundle-0.7.jar
- Tika bundle. An OSGi bundle that includes everything you need to use all Tika functionality in an OSGi environment.
我们要想做文档解析,只需引入tika-core 和 tika-parsers 即可。
当然如果您的项目是maven 构建的,那更好了。在pom里加上依赖:
- <dependency>
- <groupId>org.apache.tika</groupId>
- <artifactId>tika-core</artifactId>
- <version>0.7</version>
- </dependency>
以及
- <dependency>
- <groupId>org.apache.tika</groupId>
- <artifactId>tika-parsers</artifactId>
- <version>0.7</version>
- </dependency>
maven 会自动下载。(感谢maven官方的支持。)
- Apache tika -- 解析多种类型(word、pdf、txt 等)文件!
- Apache tika -- 解析多种类型(word、pdf、txt 等)文件!
- 使用Tika、Luke工具解析多种类型(word、pdf、txt 等)索引文件
- 关于Apache Tika解析txt文件乱码的研究
- Solr索引pdf.txt.word等文件
- Tika文本提取工具的使用(word、pdf、excel等)
- Tika文本提取工具的使用(word、pdf、excel等)
- 使用java将多种类型的文件如Word、PDF、JPG汇总到一个文档中(Word或者PDF)
- Word,Excel,pdf,txt等文件上传并提取内容
- 使用solr创建 附件[word pdf txt等文件索引]
- word、pdf等转换称txt格式
- word、pdf等转换称txt
- Tika解析rar文件
- tika 解析文件
- iOS利用QLPreviewController显示PDF,word,execl,txt等格式的文件
- java实现爬虫技术,读取txt,word,excel,ppt,pdf,html等格式的文件
- 打开各种文件,txt,pdf,jpg等
- 下载文件如word,pdf文件等
- cocoa quartz保存image的一种方式 带image格式等选项
- Visual C++ 中操纵 MS Word 123
- SQL Server 2008删除行出现错误“已更新或删除的行值要么不能使该行成为唯一行,要么改变了多个行”
- 准备踏入IT编程的学子们,你们第一门编程语言选谁? Are You Ready? Go!
- nginx源码分析(8)-模块化(3)
- Apache tika -- 解析多种类型(word、pdf、txt 等)文件!
- win8 转换格式
- 并发程序的制约
- 淡墨写韵,不守起承转合
- 让我珍藏你一生
- nginx源码分析(9)-模块化(4)
- WCF 系列:通过SvcUtil.exe生成客户端代码和配置
- win7+VirtualBox+Ubuntu+SecurityCRT教程
- Android 截屏并写入SD卡中