Java Mime Type Get getMimeType(String fileName)

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

Description

Attempts to determine the MIME type of the specified file.

License

Open Source License

Parameter

Parameter Description
fileName The name of the file to find a MIME type for.

Return

The MIME type to use for uploading this file.

Declaration

private static String getMimeType(String fileName) 

Method Source Code

//package com.java2s;
// Licensed under the Apache License, Version 2.0 (the "License");

import java.net.FileNameMap;
import java.net.URLConnection;

public class Main {
    /**/*from   ww  w .  j a  va 2  s.c o m*/
     * Attempts to determine the MIME type of the specified file. If no type is detected, falls back
     * to <code>application/octet-stream</code>.
     *
     * @param fileName The name of the file to find a MIME type for.
     * @return The MIME type to use for uploading this file.
     * @see FileNameMap#getContentTypeFor(String)
     */
    private static String getMimeType(String fileName) {
        FileNameMap fileNameMap = URLConnection.getFileNameMap();
        String mimeType = fileNameMap.getContentTypeFor(fileName);

        if (mimeType != null)
            return mimeType;
        return "application/octet-stream";
    }
}

Related

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