How do I get the File Extention for a Mime Type (Content Type)

There are tons of ways to get the Mime Type from a given InputStream or File. But given a MimeType or (in HTTP terms: content type) how do I get a list of file extensions.

Java's activation library has MimetypesFileTypeMap but that goes File Ext -> Mime Type. I need Mime Type -> File Ext.

It seems like I would have to copy the pseudo private code that is in com.sun.activation to load up the mime type mappings.


Apache comes with a mime.types file. You could parse this file and use it to map filename extensions to content types and vice versa. This file is located in the Apache Group/Apache2/conf directory.


我最终使用了可以加载的mime-types.properties文件附带的Java Mimeutil库。

链接地址: http://www.djcxy.com/p/46928.html

上一篇: 如何添加自定义MIME类型?

下一篇: 如何获取MIME类型的文件扩展名(内容类型)