`
xianbin
  • 浏览: 212846 次
  • 来自: ...
社区版块
存档分类
最新评论

Java中判断文件是否是图片文件

阅读更多
使用Image读取文件时,如果是非图像文件,则会返回null。

参考代码:
try {
    Image=ImageIO.read(new File(name));
    if (image == null) {
        valid = false;
        System.out.println("The file"+name+"could not be opened , it is not an image");
    }
} catch(IOException ex) {
    valid=false;
    System.out.println("The file"+name+"could not be opened , an error occurred.");
}
0
2
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics