views:

222

answers:

2

When coding in java, How to get the corresponding file extension if the mimeType of the file is known?

+1  A: 

make a look-up table with the mime-type as the key and the extension as the value.

Scott M.
is there any in-build library from jdk can do this for me?..
shrimpy
if you want you can build one yourself using the generic hashtable in the java.util package. see here: http://java.sun.com/javase/6/docs/api/java/util/Hashtable.html
Scott M.
@shrimpy - no general file extension to mimetype mappings exist in the JDK ... if that is what you are asking.
Stephen C
+2  A: 

There is no official list of file extension to mime type mappings. Each web server seems to maintain its own list. For example, Apache Tomcat has all the mappings defined in xml in the file $CATALINA_HOME/conf/web.xml. You could borrow the data from that list which is pretty reliable and create a Map for use in your own code.

Asaph