【转】判断是否是图片,java实现


原文链接:

https://blog.csdn.net/u010002184/article/details/74227581

private static boolean isImage(File file) throws IOException {
		BufferedImage bi = ImageIO.read(file);
		if(bi == null){
		   return false;
		}
		return true;

  

// 0.2.内容校验
public void  method(MultipartFile file){
        try {
            BufferedImage image = ImageIO.read(file.getInputStream());
            if (image == null) {
                // 图片格式不正确
                throw new RuntimeException();
            }
        } catch (IOException e) {
            throw new RuntimeException("图片格式不正确!");
        }
}

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM