Here you can find the source of getMimeType(String fileName)
static public String getMimeType(String fileName)
//package com.java2s; //License from project: Open Source License import java.net.*; public class Main { /** This gets the MIME type of a file, based on its name. If no matching MIME type is found, this method returns "untyped/binary". It calls {@link #getExactMimeType} and returns "untyped/binary" if the result is null. **/ static public String getMimeType(String fileName) { if (fileName == null) return null; String mimeType = getExactMimeType(fileName); if (mimeType == null) mimeType = "untyped/binary"; return mimeType; }/*from w w w. j a v a 2s .c om*/ /** This gets the MIME type of a file, based on its name. If no matching MIME type is found, this method returns null. It works by calling {@link URLConnection#getFileNameMap}, and does some custom processing for known types (js, tgz, css, ico, and sit) that are not in that map. **/ static public String getExactMimeType(String fileName) { if (fileName == null) return null; String mimeType = URLConnection.getFileNameMap().getContentTypeFor(fileName); if (mimeType == null) { try { String suffix = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase(); if ("js".equals(suffix)) mimeType = "text/javascript"; else if ("tgz".equals(suffix)) mimeType = "application/x-tar"; else if ("css".equals(suffix)) mimeType = "text/css"; else if ("ico".equals(suffix)) mimeType = "image/x-icon"; else if ("sit".equals(suffix)) mimeType = "application/x-stuffit"; else if ("fdx".equals(suffix)) mimeType = "application/xml"; } catch (Exception err) { } } return mimeType; } }