views:

1019

answers:

3

I have some code:

import javax.activation.MimetypesFileTypeMap;
...
..
.
String filename = "foo.xls"; // Where this can be any file name .doc, .pdf or whatever

String headerContentType = new MimetypesFileTypeMap().getContentType(filename);

It seems javax.activation.MimetypesFileTypeMap class is inside rt.jar which comes with JRE System library (jdk1.6.0_10) but not in jdk1.5.0

I would like to avoid the use of 1.6 libraries. Anyone knows an easy and quick alternative?

+2  A: 

This comes from the activation framework. This is included as standard in Java 6, but is also available as a separate download (for use with Java 1.4 and above)

Brian Agnew
Thanks. The ugly thing with Java is the feeling of adding million lines of code in libraries for just one simple function.
Sergio del Amo
I think activation.jar is relatively concise, but I take your point!
Brian Agnew
+1  A: 

The particular class is actually part of the java bean s activation framework;

JAF Download

It should not be dependant on 1.6 as far as I know. So simply download the jar, and ensure you have the mimetypes.default available on your classpath.

simon622
A: 

I've used with success this project SubLuna, it seems more complete than JAF. It uses this mime type collection : Shared MIME Info Specification which is well maintained(of course you will have to replace the file that comes with the library).

adrian.tarau