Here you can find the source of getMimeType(String fileName)
Parameter | Description |
---|---|
fileName | The file name |
public static String getMimeType(String fileName)
//package com.java2s; //License from project: Open Source License import java.net.FileNameMap; import java.net.URLConnection; import java.util.HashMap; public class Main { /**// w w w . j ava 2 s .co m * The mime types parsed from the configuration file */ private static final HashMap<String, String> mimeTypes = new HashMap<String, String>(); /** * The default java type map */ private static final FileNameMap fileNameMap = URLConnection.getFileNameMap(); /** * Get the mime type for the specified filename * * @param fileName * The file name * @return The mime type from our map, java's map or the standard mime type */ public static String getMimeType(String fileName) { if (fileName.contains(".")) { // Try our list, it is the most up to date String extension = fileName.substring(fileName.lastIndexOf('.') + 1); if (mimeTypes.containsKey(extension)) { return mimeTypes.get(extension); } } // Try the java default map String defaultMime = fileNameMap.getContentTypeFor(fileName); if (defaultMime != null) { return defaultMime; } return "application/octet-steam"; } }