文件内容提取: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));
    }
}
相关推荐
SelectDB技术团队9 小时前
面向 Agent 的高并发分析:Doris vs. Snowflake vs. ClickHouse
数据仓库·人工智能·科技·apache·知识图谱
初願致夕霞9 小时前
C++文件压缩及解压缩小程序的实现
c++·小程序·apache
小小8程序员10 小时前
Apache Doris的部署
apache
Rover.x1 天前
head table is mandatory
java·apache
SelectDB1 天前
面向 Agent 的高并发分析:Doris vs. Snowflake vs. ClickHouse
数据库·apache·agent
微学AI1 天前
时序数据库的核心概念与使用指南:Apache IoTDB 深度剖析与部署实践
apache·时序数据库·iotdb
写代码的【黑咖啡】2 天前
Apache Flink SQL 入门与常见问题解析
sql·flink·apache
小马爱打代码2 天前
Spring AI:Apache Tika 读取 Word、PPT 文档
人工智能·spring·apache
java_logo2 天前
Apache RocketMQ Docker 容器化部署指南
运维·docker·容器·kafka·kubernetes·apache·rocketmq
互联网扫地僧3 天前
Apache Doris技术原理深度解析
apache