Java Activation Mimetype Check getContentTypeFromFileName(String fileName)

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

Description

get Content Type From File Name

License

Apache License

Declaration

public static String getContentTypeFromFileName(String fileName) 

Method Source Code

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

Related

  1. copyMimeType(final MimeType original)
  2. createWildcard()
  3. equal(String string1, String string2)
  4. getContentType(String filename)
  5. getContentType(String filePath)
  6. getMimeType(final String filename)
  7. getMimetype(String filename)
  8. getMimeTypeForFileName(String filename)
  9. init()