What I'm about to share with you covers basic MIME type reading. In some cases, you don't want to use additional external libraries for your project. For this simple task, using readily available classes on Java is always a joy.
Take extra care because not all commonly known MIME types are supported. I will show you that on the last part. Let's start.
The code:
Some Test:
What else you need to know?
The list of supported MIME types are located on your JRE. Locate the file named
content-types.properties at <JRE>/lib directory. This file is being read by sun.net.www.MimeTable class which happens to be an implementation of java.net.FileNameMap. And, the default instance returned by URLConnection.getFileNameMap() function.
I never thought MIME types are existing in the JRE dir! GREAT UTILITY
ReplyDelete