文件内容提取: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));
    }
}
相关推荐
A-刘晨阳1 天前
时序数据库选型指南:从大数据视角切入,聚焦 Apache IoTDB
大数据·apache·时序数据库·iotdb
迦蓝叶1 天前
使用 Apache Jena 构建 Java 知识图谱
java·apache·知识图谱·图搜索·关系查询·关系推理
zhangkaixuan4562 天前
Apache Paimon 写入流程
java·大数据·apache·paimon
DolphinScheduler社区2 天前
Apache DolphinScheduler 3.3.2 正式发布!性能与稳定性有重要更新
大数据·开源·apache·任务调度·海豚调度·发版
SeaTunnel2 天前
Apache SeaTunnel 支持 Metalake 开发了!避免任务配置敏感信息暴露
大数据·开源·apache·个人开发·数据集成·seatunnel·看开源之夏
Mr_Art892 天前
金融行业湖仓实践:Apache Paimon 小文件治理之道
数据仓库·金融·apache
uuukashiro2 天前
数据湖优化新纪元:Apache Iceberg性能提升全攻略与腾讯云DLC实战
ai·云计算·apache·腾讯云
任风雨4 天前
13.2.1.Apache HTTP Server
http·apache·web服务器
睿本云4 天前
产品月报|睿本云10月产品功能迭代
运维·服务器·apache
HMX4045 天前
【春秋云境】CVE-2024-38856 Apache OFbiz从未授权到RCE
apache