Java Mime Type Get getMIMEType(String fileName)

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

Description

Returns the MIME type of the given file name.

License

Open Source License

Parameter

Parameter Description
fileName The file name to be analyzed

Return

The MIME type

Declaration

public static String getMIMEType(String fileName) 

Method Source Code


//package com.java2s;
//License from project: MIT License 

import java.io.File;
import java.net.FileNameMap;
import java.net.URLConnection;

public class Main {
    /**/*from  w  w w.j  a  va 2s .  c  om*/
     * Returns the MIME type of the given file name.
     * 
     * @param fileName The file name to be analyzed
     * @return The MIME type
     */
    public static String getMIMEType(String fileName) {
        FileNameMap fileNameMap = URLConnection.getFileNameMap();

        return fileNameMap.getContentTypeFor(fileName);
    }

    /**
     * Returns the MIME type of the given {@link File}.
     * 
     * @param file The {@code File} to be analyzed
     * @return The MIME type
     */
    public static String getMIMEType(File file) {
        FileNameMap fileNameMap = URLConnection.getFileNameMap();

        return fileNameMap.getContentTypeFor(file.getName());
    }
}

Related

  1. extractMimeType(byte[] imageData)
  2. getExactMimeType(String fileName)
  3. getMimeType(File file)
  4. getMimeType(String file)
  5. getMimeType(String fileName)
  6. getMimeType(String fileName)
  7. getMimeType(String fileName)
  8. getMimeTypeByFileName(String fileName)
  9. getMimeTypeForFile(File memberFile)