public class MIMETypeUtilextends ObjectThe MIMETypeUtil class provides some general purpose MIME type utilities not found in the JDK. Among other methods, this class provides the
fileExtensionForMIMEType()method, which converts a MIME type to a file extension. That method uses a traditional mime.types files, similar to the file shipped with with web servers such as Apache. It looks for a suitable file in the following locations:
- First, it looks for the file .mime.types in the user's home directory.
- Next, it looks for mime.types (no leading ".") in all the directories in the CLASSPATH
- Last, it loads a default set of mappings shipped with this library
It loads all the matching files it finds; the first mapping found for a given MIME type is the one that is used. The files are only loaded once within a given running Java VM.
The syntax of the file follows the classic mime.types syntax:
# The format is <mime type> <space separated file extensions> # Comments begin with a '#' text/plain txt text TXT text/html html htm HTML HTM ...
When mapping a MIME type to an extension,
fileExtensionForMIMEType()uses the first extension it finds in the mime.types file. MIME types that cannot be found in the file are mapped to extension ".dat".