Here you can find the source of getMimeTypeByFileName(String fileName)
public static String getMimeTypeByFileName(String fileName)
//package com.java2s; /*/*from www. j a v a2s . c om*/ * FileUtil.java * * Copyright (c) 1998 - 2005 BusinessTechnology, Ltd. * All rights reserved * * This program is the proprietary and confidential information * of BusinessTechnology, Ltd. and may be used and disclosed only * as authorized in a license agreement authorizing and * controlling such use and disclosure * * Millennium Business Suite Anywhere System. * */ import java.net.URLConnection; public class Main { private static final String DEFAULT_MIME_TYPE = "text/plain"; public static String getMimeTypeByFileName(String fileName) { if (fileName == null) return DEFAULT_MIME_TYPE; String en = URLConnection.getFileNameMap().getContentTypeFor(fileName); return en != null ? en : DEFAULT_MIME_TYPE; } }