java 判断图片的类型

// 这种方法如果遇到不是图片类型的文件会reader抛异常!  
public static void main(String[] args) throws IOException { // get image format in a file File file = new File("C:/Users/dell、/Desktop/2.txt"); // create an image input stream from the specified fileDD ImageInputStream iis = ImageIO.createImageInputStream(file); // get all currently registered readers that recognize the image format Iterator<ImageReader> iter = ImageIO.getImageReaders(iis); if (!iter.hasNext()) { throw new RuntimeException("No readers found!"); } // get the first reader ImageReader reader = iter.next(); System.out.println("Format: " + reader.getFormatName()); // close stream iis.close(); }

  

转载于:https://www.cnblogs.com/zhangzhen894095789/p/6899394.html

表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
相关推荐
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页