【轉】判斷是否是圖片,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