如何从内容类型获取文件扩展名? [英] How to get file extension from content type?

查看:32
本文介绍了如何从内容类型获取文件扩展名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Apache Tika,我有特定内容类型的文件(没有扩展名),需要重命名以具有反映内容类型的扩展名.

I'm using Apache Tika, and I have files (without extension) of particular content type that need to be renamed to have extension that reflect the content type.

知道有什么我可以使用而不是基于内容类型名称从头开始编程的吗?

Any idea if there is something I could use instead of programming that from scratch based on content type names ?

推荐答案

你想查看文件 tika-mimetypes.xml -> 查看 tika 的源代码和:

You want to look at file tika-mimetypes.xml -> check out tika's source code and :

org.apache.tika.mime.MimeTypesReader

     } else if (nodeElement.getTagName().equals(GLOB_TAG)) {
         boolean useRegex = Boolean.valueOf(nodeElement.getAttribute(ISREGEX_ATTR));
         types.addPattern(type, nodeElement.getAttribute(PATTERN_ATTR), useRegex);

然后你可以机智地工作

org.apache.tika.mime.MimeTypes

      private Patterns patterns = new Patterns(registry);

这篇关于如何从内容类型获取文件扩展名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆