文件内容提取: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));
    }
}
相关推荐
Aloudata4 小时前
数据治理选型对比:Apache Atlas vs 商业平台在存储过程解析与自动化治理的实测分析
数据挖掘·自动化·apache·元数据·数据血缘
世界尽头与你5 小时前
CVE-2017-5645_ Apache Log4j Server 反序列化命令执行漏洞
网络安全·渗透测试·log4j·apache
迎仔6 小时前
03-Apache Tez 通俗指南:MapReduce 的“高速公路”升级包
大数据·apache·mapreduce
世界尽头与你6 小时前
CVE-2025-55752_ Apache Tomcat 安全漏洞
java·安全·网络安全·渗透测试·tomcat·apache
HMX4046 小时前
【春秋云境】CVE-2025-44137 TileServer PHP v2.0任意文件读取漏洞
apache·安全漏洞·漏洞复测
迎仔6 小时前
08-Apache Iceberg 通俗指南:给“胡乱堆放”的文件加个“智能账本”
apache·iceberg
王锋(oxwangfeng)1 天前
Apache Flink 在 Kubernetes 上的高效部署与优化实践
flink·kubernetes·apache
小天源1 天前
银河麒麟操作系统 V10安装Apache Tomcat
apache
自可乐1 天前
Apache Airflow完全学习指南:从入门到精通的系统教程
人工智能·机器学习·apache
Hello.Reader1 天前
Apache Flink 网络 Buffer 调优Debloating 的边界、Buffer 生命周期
大数据·flink·apache