When coding in java, How to get the corresponding file extension if the mimeType of the file is known?
views:
222answers:
2
+1
A:
make a look-up table with the mime-type as the key and the extension as the value.
Scott M.
2009-11-12 05:33:41
is there any in-build library from jdk can do this for me?..
shrimpy
2009-11-12 05:38:43
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.
2009-11-12 06:08:17
@shrimpy - no general file extension to mimetype mappings exist in the JDK ... if that is what you are asking.
Stephen C
2009-11-12 07:47:00
+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
2009-11-12 05:49:56