Here you can find the source of getContentType(File file)
public static String getContentType(File file) throws IOException
//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; } }