code: public static String getContentType(@Nonnull File file) throws IOException {
          if (file == null) {
              throw new IllegalArgumentException("A file must be specified.");
          } else if (!file.exists()) {
              throw new IllegalArgumentException(file.getCanonicalPath() + " does not exist.");
          } else if (!file.isFile()) {
              throw new IllegalArgumentException(file.getCanonicalPath() + " is not a file.");
          }
  
          String contentType = URLConnection.guessContentTypeFromName(file.getName());
          if (contentType == null || !contentType.startsWith("image/")) {
              throw new IllegalArgumentException(file.getCanonicalPath() + " is not a supported image file.");
          }
  
          return contentType;
      }
docs: Gets the content type of the specified file representing an image.
  
  @param   file            a File pointing to an image
  @return  a content type (e.g. "image/png")
  @throws IOException      if there is an error reading the file