文件内容提取: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));
    }
}
相关推荐
Factor安全5 小时前
CVE-2025-24813 漏洞全解析|Apache Tomcat 关键路径绕过与RCE
安全·web安全·网络安全·tomcat·apache·安全威胁分析·安全性测试
天天进步一点点18 小时前
Apache Nifi安装与尝试
apache
哈哈哈哈哈哈哈哈哈...........18 小时前
【软件】在 macOS 上安装和配置 Apache HTTP 服务器
http·macos·apache
chairon2 天前
Ansible:playbook的高级用法
linux·运维·服务器·ansible·apache
三次握手四次挥手3 天前
Apache Kafka全栈技术解析
分布式·kafka·apache
IT界刘德华3 天前
Apache Flink 实战:实时流处理的最佳实践与生产级实现
大数据·flink·apache
审计侠4 天前
Apache Struts2 漏洞(CVE-2017-5638)技术分析
java·struts·web安全·apache·安全性测试
这儿有一堆花4 天前
Apache 配置负载均衡详解(含配置示例)
运维·apache·负载均衡
Steven-Russell5 天前
Apache Arrow 使用
apache
SeaTunnel5 天前
Apache SeaTunnel MCP Server:让AI成为你的ETL助手
人工智能·apache·etl