替代 javax.activation.MimetypesFileTypeMap().getContentType(filename);
我有一些代码:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这来自激活框架。 这是 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)
该特定类实际上是 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.
我已经成功使用了这个项目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).