【Java】【15】判断url对应的图片是否存在

比如一张图片的url为https://aaa.com/1.jpg,要判断该图片是否存在

 public boolean getRource(String source) {  
        try {  
            URL url = new URL(source);
            URLConnection uc = url.openConnection();
            InputStream in = uc.getInputStream();
            if (source.equalsIgnoreCase(uc.getURL().toString())) 
            in.close();  
            return true;  
        } catch (Exception e) {  
            return false;  
        }  
}

猜你喜欢

转载自www.cnblogs.com/huashengweilong/p/10803028.html
今日推荐