替代 javax.activation.MimetypesFileTypeMap().getContentType(filename);

发布于 2024-07-21 17:37:51 字数 410 浏览 3 评论 0原文

我有一些代码:

import javax.activation.MimetypesFileTypeMap;
...
..
.
String filename = "foo.xls"; // Where this can be any file name .doc, .pdf or whatever

String headerContentType = new MimetypesFileTypeMap().getContentType(filename);

似乎 javax.activation.MimetypesFileTypeMap 类位于 rt.jar 内,它随 JRE 系统库(jdk1.6.0_10)一起提供,但不在 jdk1.5.0 中

我想避免使用1.6 个库。 有人知道一个简单快捷的替代方案吗?

I have some code:

import javax.activation.MimetypesFileTypeMap;
...
..
.
String filename = "foo.xls"; // Where this can be any file name .doc, .pdf or whatever

String headerContentType = new MimetypesFileTypeMap().getContentType(filename);

It seems javax.activation.MimetypesFileTypeMap class is inside rt.jar which comes with JRE System library (jdk1.6.0_10) but not in jdk1.5.0

I would like to avoid the use of 1.6 libraries. Anyone knows an easy and quick alternative?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

荆棘i 2024-07-28 17:37:52

这来自激活框架。 这是 Java 6 中的标准配置,但也可以单独下载(与 Java 1.4 及更高版本一起使用)

This comes from the activation framework. This is included as standard in Java 6, but is also available as a separate download (for use with Java 1.4 and above)

遥远的绿洲 2024-07-28 17:37:52

该特定类实际上是 java bean 激活框架的一部分;

JAF 下载

它不应该依赖于据我所知1.6。 因此,只需下载 jar,并确保您的类路径上有 mimetypes.default 可用。

The particular class is actually part of the java bean s activation framework;

JAF Download

It should not be dependant on 1.6 as far as I know. So simply download the jar, and ensure you have the mimetypes.default available on your classpath.

半枫 2024-07-28 17:37:52

我已经成功使用了这个项目SubLuna,它看起来比JAF更完整。 它使用此 mime 类型集合:共享 MIME 信息规范 这很好维护(当然你必须替换库附带的文件)。

I've used with success this project SubLuna, it seems more complete than JAF. It uses this mime type collection : Shared MIME Info Specification which is well maintained(of course you will have to replace the file that comes with the library).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文