I'm trying to use javax.activation.MimetypesFileTypeMap
to get the content type.
For the string "image.png" it always returns "application/octect-stream" ... shouldn't it return something like "image/png" ?
javax.activation.MimetypesFileTypeMap.getDefaultFileTypeMap().getContentType("image.png");
See the Javadocs of javax.activation.MimetypesFileTypeMap
. The method looks up a file called .mime.types
in a certain order:
MIME types file search order:
The MimetypesFileTypeMap looks in various places in the user's system for MIME types file entries. When requests are made to search for MIME types in the MimetypesFileTypeMap, it searches MIME types files in the following order:
- Programmatically added entries to the MimetypesFileTypeMap instance.
- The file
.mime.types
in the user's home directory.- The file
<java.home>/lib/mime.types
.- The file or resources named
META-INF/mime.types
.- The file or resource named
META-INF/mimetypes.default
(usually found only in theactivation.jar
file).
If no file is found, getContentType
method returns application/octet-stream
:
Return the MIME type based on the specified file name. The MIME type entries are searched as described above under MIME types file search order. If no entry is found, the type "application/octet-stream" is returned.