Here you can find the source of getContentType(String filename)
public static String getContentType(String filename)
//package com.java2s; //License from project: Apache License import javax.activation.MimetypesFileTypeMap; public class Main { static private MimetypesFileTypeMap _fileTypeMap = new MimetypesFileTypeMap(); public static String getContentType(String filename) { if (filename == null || filename.length() == 0) { return "application/octet-stream"; }/*from w w w . j av a 2 s. co m*/ String contentType; if (filename.endsWith(".html") || filename.endsWith(".htm")) { contentType = "text/html"; } else if (filename.endsWith(".js")) { contentType = "text/javascript"; } else if (filename.endsWith(".css")) { contentType = "text/css"; } else if (filename.endsWith(".png")) { contentType = "image/png"; } else { contentType = _fileTypeMap.getContentType(filename); } return contentType; } }