文件内容提取:Apache Tika 2.9.2

提取各种文件的文本内容,offic image zip 等等...

Apache Tika 2.9.2 、 jdk8

基础 pom.xml

xml 复制代码
<!-- https://mvnrepository.com/artifact/org.apache.tika/tika-core -->
<dependency>
    <groupId>org.apache.tika</groupId>
    <artifactId>tika-core</artifactId>
    <version>2.9.2</version>
</dependency>
<dependency>
    <groupId>org.apache.tika</groupId>
    <artifactId>tika-parsers-standard-package</artifactId>
    <version>2.9.2</version>
</dependency>

还需要用到的 pom.xml

xml 复制代码
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
</dependency>
<dependency>
    <groupId>commons-io</groupId>
    <artifactId>commons-io</artifactId>
    <version>2.17.0</version>
</dependency>
<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-compress</artifactId>
    <version>1.26.2</version>
</dependency>
  • 注意版本号,不然会出问题

java demo

java 复制代码
@Test
public void test() throws Exception {
    InputStream inputStream = Files.newInputStream(Paths.get("text.zip"));

    BodyContentHandler contentHandler = new BodyContentHandler(-1);
    Metadata metadata = new Metadata();
    ParseContext parseContext = new ParseContext();

    new AutoDetectParser()
            .parse(inputStream, contentHandler, metadata, parseContext);

	// 提取出来的内容
    System.out.println(contentHandler);
    System.out.println("-------------------------------------------");
    // 元数据信息
    String[] names = metadata.names();
    for (String name : names) {
        System.out.println(name + ":" + metadata.get(name));
    }
}
相关推荐
摇滚侠1 天前
Apache Skywalking 实战 阅读笔记 第二章
笔记·apache·skywalking
摇滚侠2 天前
Apache Skywalking 实战 阅读笔记 第一章
笔记·apache·skywalking
小小龙学IT20 天前
Apache Airflow 2.x 深度指南:用 Python 编排一切的现代化工作流引擎
开发语言·python·apache
Shepherd061920 天前
【IT 运维】Apache 使用 mod_remoteip 恢复 Cloudflare 后的真实访客 IP
运维·tcp/ip·apache
isyangli_blog20 天前
SDN 基本应用实践 —— 使用命令行实现简易防火墙功能实验报告
服务器·php·apache
小小龙学IT21 天前
Apache Pulsar 深度解析:从架构设计到生产落地
apache
Full Stack Developme22 天前
Apache Tika 教程
java·开发语言·python·apache
laplaya22 天前
C++大型项目组件通信与依赖管理实践
c++·log4j·apache
万岳科技23 天前
教育培训小程序如何构建线上线下一体化教学体系
小程序·apache
yyuuuzz23 天前
云服务器软件部署的几个常见问题
运维·服务器·开发语言·网络·云计算·php·apache