Java Content Type Get getContentType(File file)

Here you can find the source of getContentType(File file)

Description

get Content Type

License

Apache License

Declaration

public static String getContentType(File file) 

Method Source Code

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

import java.io.File;

import java.net.URLConnection;

public class Main {
    public static String getContentType(File file) {

        String contentType = (URLConnection.guessContentTypeFromName(file
                .getName()));/* w w  w. ja v  a  2 s . c om*/

        if ("".equals(contentType) || contentType == null) {
            if (file.getName().contains(".jhtml")) {
                contentType = "text/jhtml";
            }
            if (file.getName().contains(".jap")) {
                contentType = "application/jap";
            }
            if (file.getName().contains(".css")) {
                contentType = "text/css";
            }
            if (file.getName().contains(".js")) {
                contentType = "text/javascript";
            }
        }
        return contentType;
    }
}

Related

  1. getContentType(File file)
  2. getContentType(final File file)
  3. getContentType(final String filename)
  4. getContentType(String boundary)
  5. getContentType(String file)