开发者

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

开发者 https://www.devze.com 2023-01-30 22:49 出处:网络
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.

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

精彩评论

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