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) throws IOException 

Method Source Code

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

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

public class Main {
    public static String getContentType(File file) throws IOException {
        String contentType = URLConnection.guessContentTypeFromName(file.getName());
        if (contentType == null || !contentType.startsWith("image/")) {
            throw new IllegalArgumentException(file.getCanonicalPath() + " is not a supported image file.");
        }/* w  ww. j ava2 s.  c  om*/

        return contentType;
    }
}

Related

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