Here you can find the source of getContentTypeFromFileName(String fileName)
public static String getContentTypeFromFileName(String fileName)
//package com.java2s; import javax.activation.FileTypeMap; import javax.activation.MimetypesFileTypeMap; public class Main { public static String getContentTypeFromFileName(String fileName) { FileTypeMap map = FileTypeMap.getDefaultFileTypeMap(); // TODO: figure out why PNG is missing from Java MIME types if (map instanceof MimetypesFileTypeMap) { try { ((MimetypesFileTypeMap) map) .addMimeTypes("image/png png PNG"); } catch (Exception ignored) { }//from w ww. j av a 2 s. com } return map.getContentType(fileName); } }