code: public static String getContentMimeType(final java.io.File file, final String name) throws IOException {
  
  		String mimeType;
  
  		// try name first, if not null
  		if (name != null) {
  			mimeType = mimeTypeMap.getContentType(name);
  			if (mimeType != null && !UNKNOWN_MIME_TYPE.equals(mimeType)) {
  				return mimeType;
  			}
  		}
  
  		try (final InputStream is = new BufferedInputStream(new FileInputStream(file))) {
  
  			final MediaType mediaType = new DefaultDetector().detect(is, new Metadata());
  			if (mediaType != null) {
  
  				mimeType = mediaType.toString();
  				if (mimeType != null) {
  
  					return mimeType;
  				}
  			}
  
  		} catch (NoClassDefFoundError t) {
  			logger.warn("Unable to instantiate MIME type detector: {}", t.getMessage());
  		}
  
  		// no success :(
  		return UNKNOWN_MIME_TYPE;
  	}
docs: Return mime type of given file
  
  @param file
  @param name
  @return content type
  @throws java.io.IOException