首页 > 代码库 > java中图片文件的判断

java中图片文件的判断

javax.imageio 类 ImageIOBufferedImage bi = ImageIO.read(resFile);//resFile --- InputStreamif(bi == null){    System.out.println(此文件不为图片文件);} try {//判断是否为图片文件并且返回图片的格式!                        ImageInputStream iis = ImageIO.createImageInputStream(o);                // Find all image readers that recognize the image format            Iterator<ImageReader> iter = ImageIO.getImageReaders(iis);            if (!iter.hasNext()) {                // No readers found                return null;            }                // Use the first reader            ImageReader reader = iter.next();                // Close stream            iis.close();                // Return the format name            return reader.getFormatName();}加载一个图片:ImageIcon(byte[] imageData, String description) 

 

java中图片文件的判断