Here you can find the source of isImage(File imageFile)
public static boolean isImage(File imageFile)
//package com.java2s; //License from project: Apache License import javax.imageio.ImageIO; import java.awt.*; import java.io.File; import java.io.InputStream; public class Main { public static boolean isImage(File imageFile) { if (!imageFile.exists()) { return false; }//from w w w. j av a 2s .c o m Image img = null; try { img = ImageIO.read(imageFile); if (img == null || img.getWidth(null) <= 0 || img.getHeight(null) <= 0) { return false; } return true; } catch (Exception e) { return false; } finally { img = null; } } public static boolean isImage(InputStream imageFile) { Image img = null; try { img = ImageIO.read(imageFile); if (img == null || img.getWidth(null) <= 0 || img.getHeight(null) <= 0) { return false; } return true; } catch (Exception e) { return false; } finally { img = null; } } }