Alternative to javax.activation.MimetypesFileTypeMap (). GetContentType (file name);

I have a 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 that the javax.activation.MimetypesFileTypeMap class is inside rt.jarthat comes with the JRE System library (jdk1.6.0_10), but not in jdk1.5.0

I would like to avoid using 1.6 libraries. Does anyone know an easy and quick alternative?

+3
source share
3 answers

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

+5
source

The concrete class is actually part of the java bean activation structure;

Download JAF

, 1.6. , mimetypes.default, .
+2

I have successfully used this SubLuna project , it seems more complete than JAF. It uses this collection of the mime type: General information about the MIME specification , which is well supported (of course, you will have to replace the file that comes with the library).

+1
source

Source: https://habr.com/ru/post/1708908/


All Articles