Java Mime Type Get getMimeTypeByFileName(String fileName)

Here you can find the source of getMimeTypeByFileName(String fileName)

Description

get Mime Type By File Name

License

Open Source License

Declaration

public static String getMimeTypeByFileName(String fileName) 

Method Source Code

//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;
    }
}

Related

  1. getMimeType(String file)
  2. getMimeType(String fileName)
  3. getMIMEType(String fileName)
  4. getMimeType(String fileName)
  5. getMimeType(String fileName)
  6. getMimeTypeForFile(File memberFile)