在Java中判断一个文件是否是图片和其类型的方法

ImageInputStream iis = ImageIO.createImageInputStream(new File(                "E:/1.jpg"));        Iterator iter = ImageIO.getImageReaders(iis);        if (!iter.hasNext()) {            System.out.println("null");        }else{            ImageReader reader = (ImageReader) iter.next();            System.out.println(reader.getFormatName());        }

你可能感兴趣的:(java)