开发者

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开发者_JAVA技巧 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.


I ended up using the Java Mimeutil library which comes with mime-types.properties file that you can load.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜