Java Activation Mimetype Check getContentType(String filename)

Here you can find the source of getContentType(String filename)

Description

get Content Type

License

Apache License

Declaration

public static String getContentType(String filename) 

Method Source Code


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

import javax.activation.MimetypesFileTypeMap;

public class Main {
    static private MimetypesFileTypeMap _fileTypeMap = new MimetypesFileTypeMap();

    public static String getContentType(String filename) {
        if (filename == null || filename.length() == 0) {
            return "application/octet-stream";
        }/*from   w w w .  j  av  a 2 s. co  m*/

        String contentType;

        if (filename.endsWith(".html") || filename.endsWith(".htm")) {
            contentType = "text/html";
        } else if (filename.endsWith(".js")) {
            contentType = "text/javascript";
        } else if (filename.endsWith(".css")) {
            contentType = "text/css";
        } else if (filename.endsWith(".png")) {
            contentType = "image/png";
        } else {
            contentType = _fileTypeMap.getContentType(filename);
        }

        return contentType;
    }
}

Related

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